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

前端之家收集整理的这篇文章主要介绍了运行Windows程序并检测它何时以C结尾前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
假设我运行一个应用程序,一段时间后这个应用程序将被用户关闭.是否有可能找出程序何时退出?我可以在运行该应用程序时获取它的进程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();
}
原文链接:https://www.f2er.com/windows/372167.html

猜你在找的Windows相关文章