Created
April 5, 2011 02:05
-
-
Save hpcx82/902892 to your computer and use it in GitHub Desktop.
Execute a windows program like shell execute
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int ExecuteCommand(const TCHAR* commandLine) | |
{ | |
STARTUPINFO si; | |
PROCESS_INFORMATION pi; | |
BOOL bRet; | |
DWORD lpExitCode; | |
memset(&si, 0, sizeof(si)); | |
si.cb = sizeof(si); | |
si.dwFlags = STARTF_USESHOWWINDOW; | |
si.wShowWindow = SW_HIDE; | |
bRet = CreateProcess( | |
NULL, // pointer to name of executable module | |
commandLine, // pointer to command line string | |
NULL, // process security attributes | |
NULL, // thread security attributes | |
FALSE, // handle inheritance flag | |
NORMAL_PRIORITY_CLASS, // creation flags | |
NULL, // pointer to new environment block | |
NULL, // pointer to current directory name | |
&si, // pointer to STARTUPINFO | |
&pi // pointer to PROCESS_INFORMATION | |
); | |
if(bRet) WaitForSingleObject(pi.hProcess, INFINITE); // wait for process to finish | |
GetExitCodeProcess(pi.hProcess, &lpExitCode); | |
CloseHandle(pi.hThread); | |
CloseHandle(pi.hProcess); | |
return lpExitCode; | |
} | |
// Example | |
int iRet = ExecuteCommand(_T("RegisterInventorServer.exe /install /serverhost.exe")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment