开发者

C# 2005 console application always requires elevated privileges

开发者 https://www.devze.com 2022-12-12 05:33 出处:网络
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

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.开发者_StackOverflow社区..

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消