zoukankan      html  css  js  c++  java
  • Win32 进程操作

    创建线程

    #include<iostream>
    #include<windows.h>
    
    using namespace std;
    
    DWORD WINAPI PROCESST1(LPVOID param);
    DWORD WINAPI PROCESST2(LPVOID param);
    DWORD WINAPI PROCESST3(LPVOID param);
    
    int main3()
    {
        HANDLE Thread1, Thread2, Thread3;
        Thread1 = CreateThread(NULL, 0, PROCESST1, NULL, 0, NULL);
        Thread2 = CreateThread(NULL, 0, PROCESST2, NULL, 0, NULL);
        Thread3 = CreateThread(NULL, 0, PROCESST3, NULL, 0, NULL);
        WaitForSingleObject(Thread1, INFINITE);
        WaitForSingleObject(Thread2, INFINITE);
        WaitForSingleObject(Thread3, INFINITE);
        CloseHandle(Thread1);
        CloseHandle(Thread2);
        CloseHandle(Thread3);
        return 0;
    }
    
    DWORD WINAPI PROCESST1(LPVOID param)
    {
        while (true)
        {
            cout << "THE Thread1 IS working." << endl;
            Sleep(500);
    
        }
        return 0;
    }
    
    DWORD WINAPI PROCESST2(LPVOID param)
    {
        while (true)
        {
            cout << "THE Thread2 IS working.." << endl;
            Sleep(500);
        }
        return 0;
    }
    
    DWORD WINAPI PROCESST3(LPVOID param)
    {
        while (true)
        {
            cout << "THE Thread3 IS working..." << endl;
            Sleep(500);
        }
        return 0;
    }

    进程操作:

    #include<iostream>
    #include<windows.h>
    #include<TlHelp32.h>
    
    using namespace std;
    
    //DWORD WINAPI PROCESST1(LPVOID param);
    //HANDLE mythred = ::CreateThread(NULL, 0, PROCESST1, NULL, 0, NULL);
    
    //建立进程
    void Cpro()
    {
        STARTUPINFO sw = { 0 };
        PROCESS_INFORMATION pinfo = { 0 };
        CreateProcess(
            L"G:\CPro\Project1\Debug\Project1.exe",
            NULL,
            NULL,
            NULL,
            FALSE,
            0,
            NULL,
            NULL,
            &sw,
            &pinfo
        );
        CloseHandle(pinfo.hThread);
        CloseHandle(pinfo.hProcess);
    
    };
    
    //打开与关闭进程
    void Opro()
    {
        HANDLE hproc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, 8096);
        TerminateProcess(hproc, 0);
    };
    
    //遍历进程
    void Tpro()
    {
        HANDLE hsnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
        PROCESSENTRY32 p32 = { sizeof(PROCESSENTRY32) };
    
        BOOL flg = Process32First(hsnap,&p32);
        if (flg)
        {
            do
            {
                printf("id:%d name:%ls
    ",p32.th32ProcessID,p32.szExeFile);   
            }while (Process32Next(hsnap, &p32));
        }
    
    };
    
    //遍历DLL模块
    void Spro() 
    {
       
        HANDLE hsnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, 10808);
        MODULEENTRY32 p32 = { sizeof(MODULEENTRY32) };
    
        BOOL flg = Module32First(hsnap, &p32);
        if (flg)
        {
            do
            {
                printf("Name:%ls
    ", p32.szExePath);
            } while (Module32Next(hsnap, &p32));
        }
    
    };
    
    int main()
    {
        Spro();
        return 0;
    }
  • 相关阅读:
    如何用命令将本地项目上传到github
    Mysql基本命令一
    Mysql基本命令二
    PDO操作数据库
    PHP分页
    JQuery中$.ajax()方法参数详解
    基于jquery的has()方法以及与find()方法以及filter()方法的区别详解
    IE浏览器兼容问题
    购物车的实现方式
    JS学习之路
  • 原文地址:https://www.cnblogs.com/cou1d/p/14673495.html
Copyright © 2011-2022 走看看