加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

运行Windows程序并检测它何时以C结尾

发布时间:2020-12-13 20:44:13 所属栏目:Windows 来源:网络整理
导读:假设我运行一个应用程序,一段时间后这个应用程序将被用户关闭.是否有可能找出程序何时退出?我可以在运行该应用程序时获取它的进程ID吗? 这是 here的引用: #include windows.h#include stdio.h#include tchar.h#include conio.hvoid _tmain( int argc,TCHA
假设我运行一个应用程序,一段时间后这个应用程序将被用户关闭.是否有可能找出程序何时退出?我可以在运行该应用程序时获取它的进程ID吗?
这是 here的引用:
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include <conio.h>

void _tmain( int argc,TCHAR *argv[] )
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
STARTUPINFO sj;
PROCESS_INFORMATION pj;

ZeroMemory( &si,sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi,sizeof(pi) );

ZeroMemory( &sj,sizeof(sj) );
sj.cb = sizeof(sj);
ZeroMemory( &pj,sizeof(pj) );

// Start the child process p1.exe. Make sure p1.exe is in the
// same folder as current application. Otherwise write the full path in first argument.
if(!CreateProcess(L".p1.exe",NULL,FALSE,&sj,&pj))
{
printf( "Hello CreateProcess failed (%d)n",GetLastError() );
getch();
return;
}

// Start child process p2.exe. Make sure p2.exe is in the
// same folder as current application. Otherwise write the full path in first argument.
if(!CreateProcess(L".p2.exe",&si,&pi))
{
printf( "CreateProcess2 failed (%d)n",GetLastError() );
getch();
return;
}

// Wait until child processes exit.
WaitForSingleObject( pi.hProcess,INFINITE );
WaitForSingleObject( pj.hProcess,INFINITE );

// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
CloseHandle( pj.hProcess );
CloseHandle( pj.hThread );
getch();
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读