tags:

views:

50

answers:

2

1) is it possible to gain admin privs (i.e. "Run as administrator") during runtime, or must the EXE launch this way from the start?

2) how do I request admin privs, so the user is given the prompt to allow or disallow it?

Thank you -Carl

+1  A: 

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://search.cpan.org/~mdootson/Win32-Exe-0.12_01/lib/Win32/Exe/Manifest.pm ).

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

PeterK
I don't always need elevated privs; I want to request it when the user clicks a button.
tenfour
Oh i see, then my edit is probably irelevant. Leaving the answer here as somebody might find it useful.
PeterK
+1  A: 

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);
steelbytes
I don't think it's possible to change execution level during runtime; my solution was indeed to restart the application with elevation. Thanks.
tenfour