English 中文(简体)
C# 2005 console application always requires elevated privileges
原标题:

I am trying to build an automation application in C# 2005 express edition under windows vista. Problem is, Whenever I try to run this application, either from IDE or directly compiled executable under vista, it asks for elevated admin privileges, same executable runs under XP normally though!

I m unable to understand if this problem due to manifest or something else...

Thanks,

问题回答

Firstly, I would update to 2008 Express; 2005 Express is no longer available for download, but 2008 Express can still target .NET 2.0, in addition to giving you 3.0/3.5 goodness. And it is still free. Actually, 2010 Express is just around the corner! In particular, you ll find it increasingly hard to find people who can answer 2005 Express IDE-specific issues, simply because few people have 2005 Express still installed.


Add an application manifest file (via the IDE) - it will appear as app.manifest; it should add (by default):

<requestedExecutionLevel level="asInvoker" uiAccess="false" />

Which should (IIRC) help - but a: where is the app running from, and b: what does it do? (does it try to edit the registry, etc).

Additionally to Marc s answer: If the executable has i.e. setup or install as part of it s name, the UAC asks for admin privileges regardless of a manifest. The only work around that is to rename the .exe to something that does not contain these keywords.

Edit: Update is such a keyword too. Please see also this Technet article about UAC.

If your application attempts to do things that require elevated privileges (e.g. write to the Program Files folder or some areas of the registry), it will need to ask for elevation or it ll fail. Under XP it won t ask for elevation at all; it ll just fail if it doesn t have the permissions it needs to run (but usually people run with administrative privileges under XP, so this isn t often a problem)

To add one "gotcha" to the existing answers: If you use the file properties (Compatibility tab) on your .exe to force it to "run as administrator", it will always ask for elevation when it is run. Unintuitively, this is applied permanently to the pathname, so even if you delete the .exe and install a new one, the "as admin" setting will still apply! You have to specifically open the properties and disable that property to remove it again.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签