Archive: RunAsAdmin


RunAsAdmin
if i'm not mistaken, i cannot use the UAC plugin to have an installer in user mode execute a file as admin. is there any other way this can be done? the executed program would ideally request admin rights from the user first.

i came across this, not sure if this is a possible solution. anyway, i would prefer not having to use the registry for such a simple task.


To ExecWait an exe as admin, see here: http://forums.winamp.com/showthread.php?t=287227
I guess to Exec without Wait you can just call shellexecuteex without worrying about process handles.

(I found it by using the search function. Keyword 'admin', search in titles only, show results as threads, NSIS forum only.)

(Note: Running an exe As Admin will ALWAYS require the user to enter credentials. It would be bad if you could just run something as admin without the admin password!)


i guess i'd have to make a system call? i have no idea how these work. anyone who could provide a reallife example please?


Best way (if possible) is for the program itself to request administrator privileges using a requestExecutionLevel manifest and code to test the current user is an administrator.

Stu


so now i'm using ShellExecWait and it does the job for ExecWait.

however, i looking for the same to perform a simple Exec. i commented the following portion of the code and it works as desired.

${If} $1 <> 0
System::Call '*$0(is,i,i,i,i,i,i,i,i,i,i,i,i,i,i.r1)' ;stack value not really used, just a fancy pop ;)
System::Call 'kernel32::WaitForSingleObject(ir1,i-1)'
System::Call 'kernel32::GetExitCodeProcess(ir1,*i.s)'
System::Call 'kernel32::CloseHandle(ir1)'
${EndIf}


as i don't really understand this, i was wondering if there's more code i could leave?

If you don't need to wait for the process to exit, you don't want SEE_MASK_NOCLOSEPROCESS (0x00000040) for the 2nd member (fMask) of the SHELLEXECUTEINFO struct.

Stu


Why make this more complicated than it has to be? To perform a ShellExecute without waiting you can just use the ExecShell command...