2 * PROJECT: ReactOS Automatic Testing Utility
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Class able to create a new process and closing its handles on destruction (exception-safe)
5 * COPYRIGHT: Copyright 2009-2019 Colin Finck (colin@reactos.org)
11 * Constructs a CProcess object and uses the CreateProcessW function to start the process immediately.
14 * A std::wstring containing the command line to run
17 * Pointer to a STARTUPINFOW structure containing process startup information
19 CProcess::CProcess(const wstring
& CommandLine
, LPSTARTUPINFOW StartupInfo
)
21 auto_array_ptr
<WCHAR
> CommandLinePtr(new WCHAR
[CommandLine
.size() + 1]);
23 wcscpy(CommandLinePtr
, CommandLine
.c_str());
25 if(!CreateProcessW(NULL
, CommandLinePtr
, NULL
, NULL
, TRUE
, NORMAL_PRIORITY_CLASS
, NULL
, NULL
, StartupInfo
, &m_ProcessInfo
))
26 TESTEXCEPTION("CreateProcessW failed\n");
30 * Destructs a CProcess object, terminates the process if running, and closes all handles belonging to the process.
34 TerminateProcess(m_ProcessInfo
.hProcess
, 255);
35 CloseHandle(m_ProcessInfo
.hThread
);
36 CloseHandle(m_ProcessInfo
.hProcess
);