#include "stdafx.h"
#include <WINDOWS.H>
int main(int argc, char* argv[])
{
SECURITY_ATTRIBUTES sa_p;
sa_p.nLength = sizeof(sa_p);
sa_p.lpSecurityDescriptor = NULL;
sa_p.bInheritHandle = TRUE;
SECURITY_ATTRIBUTES sa_t;
sa_t.nLength = sizeof(sa_t);
sa_t.lpSecurityDescriptor = NULL;
sa_t.bInheritHandle = TRUE;
STARTUPINFOA si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
//si.dwFlags = STARTF_USESHOWWINDOW; // 指定wShowWindow成员有效
//si.wShowWindow = TRUE; // 此成员设为TRUE的话则显示新建进程的主窗口,
char s1[50] = {0};
char s2[255] = {0};
TCHAR stcAppName[] = TEXT("C://Program Files//Internet Explorer//iexplore.exe");
BOOL res1 = CreateProcess(NULL,stcAppName,&sa_p,&sa_t,TRUE,CREATE_NEW_CONSOLE,NULL,NULL,&si,&pi);
if (!res1)
{
DWORD dwcode = GetLastError();
printf("%x\n",dwcode);
}
sprintf(s1,"%x %x",pi.hProcess,pi.hThread);
//sprintf(s2,"F:/zzz1.exe %s",s1);
sprintf(s2,"F:\\Program Files (x86)\\Microsoft Visual Studio\\MyProjects\\zzz1\\Debug\\zzz1.exe %s",s1);
////F:\Program Files (x86)\Microsoft Visual Studio\MyProjects\zzz1
BOOL res2 = CreateProcess(NULL,s2,NULL,NULL,TRUE,CREATE_NEW_CONSOLE,NULL,NULL,&si,&pi);
if (!res2)
{
DWORD dwcode = GetLastError();
printf("%x\n",dwcode);
}
getchar();
printf("Hello World!\n");
return 0;
}
#include "stdafx.h"
#include <windows.h>
int main(int argc, char* argv[])
{
char st1[50] = {0};
char st2[50] = {0};
DWORD hd_process = 0;
DWORD hd_thread = 0;
sprintf(st1,"%s",argv[1]);
sscanf(st1,"%x",&hd_process);
sprintf(st2,"%s",argv[2]);
sscanf(st2,"%x",&hd_thread);
printf("进程名:%s\n",argv[0]);
printf("继承子进程进程句柄:%x\n",hd_process);
printf("继承子进程线程句柄:%x\n",hd_thread);
Sleep(10000);
printf("挂起子线程\n");
SuspendThread((HANDLE)hd_thread);
Sleep(10000);
printf("恢复线程\n");
ResumeThread((HANDLE)hd_thread);
Sleep(10000);
printf("关闭子进程中。。。\n");
TerminateProcess((HANDLE)hd_process,1);
WaitForSingleObject((HANDLE)hd_process,INFINITE);
printf("关闭子进程成功\n");
getchar();
return 0;
}