windows-nt/Source/XPSP1/NT/admin/wmi/wbem/winmgmt/ntsdext/utils.cpp

52 lines
901 B
C++
Raw Normal View History

2020-09-26 03:20:57 -05:00
/*++
Copyright (C) 1997-2001 Microsoft Corporation
Module Name:
Abstract:
History:
--*/
#include "precomp.h"
#include "utils.h"
DWORD WaitOnProcess(char *szExe, char *szParams, bool bHidden/*=true*/, bool bWait/*=true*/)
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
BOOL bRet;
DWORD dwExitCode=STILL_ACTIVE;
ZeroMemory(&si,sizeof(si));
si.cb=sizeof(si);
bRet=CreateProcess(szExe,szParams,NULL,NULL,NULL,
((bHidden)?DETACHED_PROCESS:CREATE_NEW_CONSOLE),NULL,NULL,&si,&pi);
//wait until done
//===============
if (bRet && bWait)
{
while(dwExitCode==STILL_ACTIVE)
{
Sleep(100); //don't be a pig
GetExitCodeProcess(pi.hProcess,&dwExitCode);
}
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
}
else
{
dwExitCode=(bRet)?0:1;
}
return dwExitCode;
}