// cereatepross.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<iostream>
//#include<WinBase.h>
#include<Windows.h>
#include<TlHelp32.h>
#include<atlstr.h>
using namespace std;
BOOL FindAndKillProcessByName(LPCTSTR strProcessName);
int _tmain(int argc, _TCHAR* argv[])
{
// 临时变量
CStringA sCommandLine;
wchar_t cWindowsDirectory[MAX_PATH];
char cCommandLine[MAX_PATH];
DWORD dwExitCode;
PROCESS_INFORMATION pi;
STARTUPINFO si = {sizeof(si)};
// 得到Windows文件夹目录
GetWindowsDirectory(cWindowsDirectory, MAX_PATH);
// 启动"记事本"程序的命令行
sCommandLine = CStringA(cWindowsDirectory) + L"\\NotePad.exe";
::strcpy(cCommandLine, sCommandLine);
// 启动"记事本"作为子进程
wchar_t pszMultiByteString[MAX_PATH];
MultiByteToWideChar( CP_UTF8, 0, cCommandLine, /*sizeof(pszTemp)*/ -1, pszMultiByteString, MAX_PATH );
BOOL ret = CreateProcess(NULL,pszMultiByteString, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
//创建的子进程句柄存放在pi中
if (ret) {
// 关闭子进程的主线程句柄
CloseHandle(pi.hThread);
// 等待子进程的退出
WaitForSingleObject(pi.hProcess,INFINITE);
// 获取子进程的退出码
GetExitCodeProcess(pi.hProcess,&dwExitCode);
// 关闭子进程句柄
CloseHandle(pi.hProcess);
}
BOOL FindAndKillProcessByName(LPCTSTR strProcessName);
return 0;
}