windows_32_ProcUse 进程使用
// windows_32_ProcUse.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <windows.h>
void Wait( )
{
//创建一个进程
STARTUPINFO si = { 0 };
PROCESS_INFORMATION pi = { 0 };
si.cb = sizeof( si );
CreateProcess( "C:\\Program Files\\Microsoft Games\\Minesweeper\\MineSweeper.exe", NULL, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi );
printf( "Winmine is running\n" );
//等候进程结束
WaitForSingleObject( pi.hProcess, INFINITE );
printf( "Winmine is stop\n" );
}
void Terminate( DWORD dwProcID)
{
//3、结束进程
//ExitProcess
//TerminateProcess
HANDLE hProc = OpenProcess( PROCESS_ALL_ACCESS, FALSE, dwProcID );
TerminateProcess( hProc, 0 );
}
void Create( )
{
//1、创建进程
//WinExec 16位windows的东西,退伍了
//ShellExecute 带有环境参数的命令行,尽量用这个
//CreateProcess 执行一个EXE可执行文件,创建一个进程以及它的主线程
STARTUPINFO si = { 0 };
PROCESS_INFORMATION pi = { 0 };
si.cb = sizeof( si ); //还得给它赋点值
CreateProcess( "C:\\Program Files\\Microsoft Games\\Minesweeper\\MineSweeper.exe", NULL, NULL, NULL,
FALSE, 0, NULL, NULL, &si, &pi );
//输出信息
printf( "Process Handle: %p\n", pi.hProcess );
printf( "Process ID: %d\n", pi.dwProcessId );
printf( "Thread Handle: %p\n", pi.hThread );
printf( "Thread ID: %d\n", pi.dwThreadId );
}
int _tmain(int argc, _TCHAR* argv[])
{
Create( );
Terminate( 8244 );
Wait( );
return 0;
}
时间: 2024-10-10 13:00:43