码迷,mamicode.com
首页 > 编程语言 > 详细

C++.进程3

时间:2020-03-10 23:28:54      阅读:55      评论:0      收藏:0      [点我收藏+]

标签:roc   try   close   out   进程   string   c++   UNC   include   

#include <vector>
BOOL TraversalProcess3(OUT std::vector<DWORD> &vec)
{
    vec.clear();
    try
    {
        HANDLE hProcess = 0;
        for (DWORD i = 0; i < WORD_MAX; i += 4)
        {
            hProcess = ::OpenProcess(PROCESS_ALL_ACCESS, 0, i);
            if (hProcess)
            {
                vec.push_back(i);
                CloseHandle(hProcess);
                hProcess = 0;
            }
        }
    }
    catch (...)
    {
        OutputDebugStringA(__FUNCTION__);
        return 0;
    }
    return vec.size() > 0;
}

int main()
{
    std::vector<DWORD> vec;
    std::cout << TraversalProcess3(vec) << endl;
    for each (DWORD var in vec)
    {
        printf("%d\t", var);
        printf("\r\n");
    }

    return 0;
}

C++.进程3

标签:roc   try   close   out   进程   string   c++   UNC   include   

原文地址:https://www.cnblogs.com/dailycode/p/12459598.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!