• WIN32 子进程继承子进程


    #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;
    }
  • 相关阅读:
    UDS 诊断协议 $36
    UDS 诊断协议 $34
    RH850 CS+工程 定义常量变量到指定ROM地址
    关于ARM 架构汇编指令
    RH850 FDL的使用
    robotframework Selenium2+RFS自动化测试
    虫师 博客园 http://www.cnblogs.com/fnng/
    Excel数据比对-批量数据比对
    web自动化测试 Selenium2 Java自动化测试实战9_3
    loadrunner11 +Win7 + 支持ie9,录制成功
  • 原文地址:https://www.cnblogs.com/ganxiang/p/13220807.html
Copyright © 2020-2023  润新知