Use CreateProcess to Run a Batch File

Some problems: You need to pass the /C option to cmd.exe in order to make it execute the .bat file. The second parameter to CreateProcess must be a modifiable string. Not a literal. You need to escape backslash characters in literals. lpszCurrentVariable points to the buffer returned by GetEnvironmentStrings. You cannot modify that buffer. You … Read more

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