我想使用cpp从任务管理器的父进程名称中获取子进程 [英] I want to get the child process from the parent process name from task manager using cpp

查看:91
本文介绍了我想使用cpp从任务管理器的父进程名称中获取子进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个代码告诉我父进程是否在任务管理器中运行              

I have a code which tells me whether my parent process is running in task manager or not             

int main(无效)

{

    bool bCallForMain = true;

      CheckIfApplicationAlreadyRunning(bCallForMain);

        if(bCallForMain)

        {

            _tprintf(TEXT(" true - app alredy runnin"));

       }

        else

        {

            _tprintf(TEXT(" false - not running"));

       }
$


   }

bool CheckIfApplicationAlreadyRunning(bool& appRunning)

{

$
    HANDLE hProcessSnap;

   处理hProcess;

    PROCESSENTRY32 pe32;

    DWORD dwPriorityClass;



    //拍摄系统中所有进程的快照。

    hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);

    if(hProcessSnap == INVALID_HANDLE_VALUE)

  {

        _tprintf(TEXT(" CreateToolhelp32Snapshot(of processes)"));

       返回(FALSE);

  }


    //在使用之前设置结构的大小。

    pe32.dwSize = sizeof(PROCESSENTRY32);



    //检索有关第一个流程的信息,

    //如果不成功则退出

  if(!Process32First(hProcessSnap,& pe32))

  {

      _tprintf(TEXT(QUOT; Process32First")); //显示失败原因

      CloseHandle的(hProcessSnap);          //清理快照对象

     返回(FALSE);

 }



    //现在浏览流程快照,并以
    //依次显示每个流程的信息

    while(Process32Next(hProcessSnap,& pe32))

    {

$
        std :: wstring进程(L" VeracityNXT.exe");

        if(pe32.szExeFile == processs)

        {

            appRunning = true;

           休息;

        }¥b $ b       否则

        {

            appRunning = false;

        }¥b $ b     } 

    CloseHandle(hProcessSnap);

   返回(TRUE);

 }

int main(void)
{
    bool bCallForMain=true;
     CheckIfApplicationAlreadyRunning(bCallForMain);
       if (bCallForMain)
       {
           _tprintf(TEXT("true - app alredy runnin"));
       }
       else
       {
           _tprintf(TEXT("false - not running"));
       }

   }
bool CheckIfApplicationAlreadyRunning(bool& appRunning)
{

    HANDLE hProcessSnap;
    HANDLE hProcess;
    PROCESSENTRY32 pe32;
    DWORD dwPriorityClass;

    // Take a snapshot of all processes in the system.
    hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
   if (hProcessSnap == INVALID_HANDLE_VALUE)
  {
       _tprintf(TEXT("CreateToolhelp32Snapshot (of processes)"));
        return(FALSE);
  }

    // Set the size of the structure before using it.
    pe32.dwSize = sizeof(PROCESSENTRY32);

    // Retrieve information about the first process,
    // and exit if unsuccessful
 if (!Process32First(hProcessSnap, &pe32))
  {
     _tprintf(TEXT("Process32First")); // show cause of failure
     CloseHandle(hProcessSnap);          // clean the snapshot object
      return(FALSE);
 }

    // Now walk the snapshot of processes, and
    // display information about each process in turn
    while (Process32Next(hProcessSnap, &pe32))
    {

        std::wstring processs(L"VeracityNXT.exe");
        if (pe32.szExeFile == processs)
        {
            appRunning = true;
            break;
        }
        else
        {
            appRunning = false;
        }
     } 
    CloseHandle(hProcessSnap);
    return(TRUE);
 }

我想获取父进程的子进程。并创建它的实例

My i want to get the child process of the parent one. and create its instance

我该怎么做?

请帮帮我

推荐答案

PROCESSENTRY32结构包括父进程的进程ID。

The PROCESSENTRY32 structure includes the process id of the parent process.

另一种选择是使用WMI获取ParentProcessid 
Win32_Process类
的属性b $ b

Another option is to use WMI to obtain the ParentProcessid  property of Win32_Process class


这篇关于我想使用cpp从任务管理器的父进程名称中获取子进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆