Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Simple CreateProcessW()
#include <stdio.h> //c header for things like Printf
#include <Windows.h> //Added in order to use windows apis; could also be added to pch.h
int main()
wchar_t cmd[] = L"notepad.exe";//unicode string as parameters for strings are unicode for CreateProcessW
STARTUPINFO si = { sizeof(si) };
//memset(&si, 0, sizeof(si));//These 2 lines are the same as the init done via C style shortcut in the line above
//si.cb = sizeof(ci)
BOOL OK = CreateProcessW(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
if (OK)// check if Process is created
printf("Applicaiton is running\n");
printf("PID = %d\n", pi.dwProcessId);
//Wait forever till Process object is signaled (terminated)
DWORD status = WaitForSingleObject(pi.hProcess, INFINITE);
if (status == WAIT_OBJECT_0)//The state of the specified object is signaled.
printf("PID = %d is closed!\n", pi.dwProcessId);
printf("Application NOT running! \t Error code %d", GetLastError());
//Add breakpoint here to prevent console from automatically closing after debugging is finished
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment