How to run application which requires admin rights from one that doesn’t have them [closed]

Real problem: (from Wikipedia: http://en.wikipedia.org/wiki/User_Account_Control) An executable that is marked as “requireAdministrator” in its manifest cannot be started from a non-elevated process using CreateProcess(). Instead, ERROR_ELEVATION_REQUIRED will be returned. ShellExecute() or ShellExecuteEx() must be used instead. (BTW, ERROR_ELEVATION_REQUIRED error == 740) Solution: (same site) In a native Win32 application the same “runas” verb can be … Read more

How do I run a command-line program in Delphi?

An example using ShellExecute(): procedure TForm1.Button1Click(Sender: TObject); begin ShellExecute(0, nil, ‘cmd.exe’, ‘/C find “320” in.txt > out.txt’, nil, SW_HIDE); Sleep(1000); Memo1.Lines.LoadFromFile(‘out.txt’); end; Note that using CreateProcess() instead of ShellExecute() allows for much better control of the process. Ideally you would also call this in a secondary thread, and call WaitForSingleObject() on the process handle to … Read more

How can I run a child process that requires elevation and wait?

Use ShellExecuteEx, rather than ShellExecute. This function will provide a handle for the created process, which you can use to call WaitForSingleObject on that handle to block until that process terminates. Finally, just call CloseHandle on the process handle to close it. Sample code (most of the error checking is omitted for clarity and brevity): … Read more