Requesting Administrator privileges during runtime

拈花ヽ惹草 提交于 2019-12-12 12:09:33

问题


How do I request Administrator privileges during runtime so the user is given the prompt to allow or disallow it?


回答1:


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




回答2:


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);


来源:https://stackoverflow.com/questions/3405319/requesting-administrator-privileges-during-runtime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!