I need to create a process and get a handle and PID of it.
Here is my code:
STARTUPINFOW SI;
PROCESS_INFORMATION PI;
SI.cb = sizeof(SI);
std::wstring Name = L"Dummy";
if (!::CreateProcessW(Name.c_str(), NULL, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &SI, &PI))
{
std::wcout << L"Failed to create a process";
}
HANDLE hDummy = ::OpenProcess(PROCESS_ALL_ACCESS, TRUE, PI.dwProcessId);
It outputs "Failed to create a process"
in output Window. I can't see a process in Process Explorer and all values of PI are still 0.
It also gives me this message: Exception thrown at 0x00007FFA5202C286 (ntdll.dll) in PEX.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.
The problem was solved by making an array of WCHAR
, and passing it to the second parameter of CreateProcessW
, instead of the first one