process
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
How to send keys instead of characters to a process?
You are mixing input streams with control signals. A console process has a default input stream which you can control with the StandardInput, as you already know. But Ctrl-C and Ctrl-Break are not characters sent to the process through this stream, but instead they are instead control signals that the process receives using the registered … Read more
Why does StandardOutput.Read() block when StartInfo.RedirectStandardInput is set to true?
i fought and fought with this just last week actually… for some reason anything other than the Read() call (ReadToEnd() was not what i needed) seemed to block and never return. here’s what i did to finally get it to “work”: snip 1: private bool ThreadExited = true; private bool ExitThread = false; private void … 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
To run cmd as administrator along with command?
As @mtijn said you’ve got a lot going on that you’re also overriding later. You also need to make sure that you’re escaping things correctly. Let’s say that you want to run the following command elevated: dir c:\ First, if you just ran this command through Process.Start() a window would pop open and close right … Read more
How to wait on all child (and grandchild etc) process spawned by a script
You can use wait to wait for all the background processes started by userscript to complete. Since wait only works on children of the current shell, you’ll need to source their script instead of running it as a separate process. ( source userscript; wait ) Sourcing the script in an explicit subshell should simulate starting … 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