开发者

Requesting Administrator privileges during runtime

How do I request Administrator privil开发者_JAVA百科eges during runtime so the user is given the prompt to allow or disallow it?


if you want it in response to a button (eg, like 'show processes for all users' in task manager), you have to resart your app using the following method

ShellExecute(0,L"runas",exepath,0,0,SW_SHOWNORMAL);


This information is written in the exe file manifest. You must use the requestedExecutionLevel field (but not sure about that - try setting it to highestAvailable and see if it does what you need). See for example here for more information (somewhat older article but still valid): http://blogs.msdn.com/b/cjacks/archive/2006/09/08/exploring-manifests-part-2-default-namespaces-and-uac-manifests-in-windows-vista.aspx

There are tools in Visual Studio which allow you to embed your own manifest or even just edit it. Also there is a tool written in Perl ( http://metacpan.org/pod/Win32::Exe::Manifest ).

EDIT: see this article for more info: http://www.codeproject.com/Articles/66259/Requesting-Admin-Approval-at-Application-Start.aspx

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜