Tag: process

C

Create a process in C

#include <stdlib.h> #include <stdio.h> #include <windows.h>     int main() { STARTUPINFO startInfo; PROCESS_INFORMATION procInfo;   //lock user WCHAR cmd[50] = L"rundll32.exe user32.dll, LockWorkStation\0";   SecureZeroMemory(&startInfo, sizeof(startInfo)); startInfo.cb = sizeof(startInfo); SecureZeroMemory(&procInfo, sizeof(procInfo));   if (CreateProcess(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &startInfo, &procInfo) != 0) return GetLastError();   CloseHandle(procInfo.hProcess); CloseHandle(procInfo.hThread);   return EXIT_SUCCESS; }#include …

C, Microsoft Windows

Get current process id in C

GetCurrentProcessId function #include <stdlib.h> #include <stdio.h> #include <windows.h>   int main(void) { printf("%lu", GetCurrentProcessId()); return EXIT_SUCCESS; }#include <stdlib.h> #include <stdio.h> #include <windows.h> int main(void) { printf("%lu", GetCurrentProcessId()); return EXIT_SUCCESS; } Get current process id with C in Linux.

C

How to determine whether specific processes are running or not

Let’s see how we can check if specific processes are already running in the system and then decide what we would like to do (exit for example). Useful links CreateToolhelp32Snapshot Process32First Process32Next //.. static char* const ProcessesNotAllowed[] = { "blahblah1", "blahblah2" }; //.. void CheckIfProcsRunning() { PROCESSENTRY32 pe; HANDLE h; int i = 0; int …

C#

Restart Explorer Process using c#

First of all, you have to kill all running processes of explorer.exe(usually only one) and then start it with full path specified, otherwise a new explorer window will open. void _restart_explorer() { try { foreach (Process p in Process.GetProcesses()) { try { Process[] exp = Process.GetProcessesByName("explorer"); foreach (Process explorer in exp) explorer.Kill(); } catch { …

C

Get Process ID by name

We are going to use the following functions: CreateToolhelp32Snapshot Process32First Process32Next CloseHandle Source #include <stdio.h> #include <stdlib.h> #include <windows.h> #include <tlhelp32.h> #define INVALID_PID_VALUE -1;   DWORD GetProcessID( const char * processName );   int main(int argc, char* argv[]) { DWORD pid;   if(argc>1) { printf("rnSearching for the process id of ‘%s’ …rn", argv[1]);   pid …

C#

How to terminate a process in c#

By name foreach (Process p in Process.GetProcessesByName("process_name")) { try { p.Kill(); p.WaitForExit(); } catch { } }foreach (Process p in Process.GetProcessesByName("process_name")) { try { p.Kill(); p.WaitForExit(); } catch { } } By id try { Process p = Process.GetProcessById(process_id); p.Kill(); p.WaitForExit(); } catch { }try { Process p = Process.GetProcessById(process_id); p.Kill(); p.WaitForExit(); } catch { …

Microsoft Windows

Kill process on remote computer

We can kill processes running on a remote pc using the taskkill command. Usage: Taskkill /S [ip_address] /U [username] /P [password] /PID [processid]Taskkill /S [ip_address] /U [username] /P [password] /PID [processid] Taskkill /S [ip_address] /U [username] /P [password] /F /IM [iamgename]Taskkill /S [ip_address] /U [username] /P [password] /F /IM [iamgename] Taskkill /S [ip_address] /U [username] …