How to create a process in C++ on Windows?

regasm.exe(Assembly Registration Tool) makes changes to the Windows Registry, so if you want to start regasm.exe as elevated process you could use the following code: #include “stdafx.h” #include “windows.h” #include “shellapi.h” int _tmain(int argc, _TCHAR* argv[]) { SHELLEXECUTEINFO shExecInfo; shExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); shExecInfo.fMask = NULL; shExecInfo.hwnd = NULL; shExecInfo.lpVerb = L”runas”; shExecInfo.lpFile = L”regasm.exe”; shExecInfo.lpParameters … Read more

kill process with python

You can retrieve the process id (PID) given it name using pgrep command like this: import subprocess import signal import os from datetime import datetime as dt process_name = sys.argv[1] log_file_name = sys.argv[2] proc = subprocess.Popen([“pgrep”, process_name], stdout=subprocess.PIPE) # Kill process. for pid in proc.stdout: os.kill(int(pid), signal.SIGTERM) # Check if the process that we killed … Read more

How to get the starting/base address of a process in C++?

Here’s another way, written in Visual Studio 2015 but should be backwards compatible. void GetBaseAddressByName(DWORD processId, const _TCHAR *processName) { _TCHAR szProcessName[MAX_PATH] = _TEXT(“<unknown>”); HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processId); if (NULL != hProcess) { HMODULE hMod; DWORD cbNeeded; if (EnumProcessModulesEx(hProcess, &hMod, sizeof(hMod), &cbNeeded, LIST_MODULES_32BIT | LIST_MODULES_64BIT)) { GetModuleBaseName(hProcess, hMod, szProcessName, sizeof(szProcessName) / … Read more

How to get hWnd of window opened by ShellExecuteEx.. hProcess?

First use WaitForInputIdle to pause your program until the application has started and is waiting for user input (the main window should have been created by then), then use EnumWindows and GetWindowThreadProcessId to determine which windows in the system belong to the created process. For example: struct ProcessWindowsInfo { DWORD ProcessID; std::vector<HWND> Windows; ProcessWindowsInfo( DWORD … Read more