'system()' is a les--than-optimal approach towards this problem, since it opens a console window. 'CreateProcess()' is what the Windows SDK offers, and wrapped up, you can use it like
DWORD ExecuteAndWaitForCompletio
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
BOOL bRes;
DWORD dwCode = 0;
ZeroMemory ( &si, sizeof ( STARTUPINFO));
si.cb = sizeof ( STARTUPINFO);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_SHOWNORMAL;
bRes = CreateProcess ( NULL,
pszCmd,
NULL,
NULL,
TRUE,
NORMAL_PRIORITY_CLASS,
NULL,
NULL,
&si,
&pi
);
while ( WAIT_OBJECT_0 != MsgWaitForMultipleObjects ( 1,
&pi.hProcess,
FALSE,
INFINITE,
QS_ALLINPUT
)
)
{
while ( PeekMessage ( &msg, NULL, 0, 0, PM_REMOVE))
{
DispatchMessage ( &msg);
}
}
GetExitCodeProcess ( pi.hProcess, &dwCode);
CloseHandle ( pi.hProcess);
CloseHandle ( pi.hThread);
return ( dwCode);
}
Use it like
ExecuteAndWaitForCompletio
If you don't need to wait for the process to finish, just make that
BOOL Execute ( LPSTR pszCmd)
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
BOOL bRes;
DWORD dwCode = 0;
ZeroMemory ( &si, sizeof ( STARTUPINFO));
si.cb = sizeof ( STARTUPINFO);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_SHOWNORMAL;
bRes = CreateProcess ( NULL,
pszCmd,
NULL,
NULL,
TRUE,
NORMAL_PRIORITY_CLASS,
NULL,
NULL,
&si,
&pi
);
CloseHandle ( pi.hProcess);
CloseHandle ( pi.hThread);
return bRes;
}
Use it like
Execute("\"C:\Program Files\Webconference.com\Re
BTW, the path names need to be quoted if they contain spaces.
Main Topics
Browse All Topics





by: avizitPosted on 2007-07-19 at 18:27:56ID: 19527893
you use the "system" function
corder\Rec order.exe /s");
for the same example above in C++ you would do
system("C:\Program Files\Webconference.com\Re