#include <tlhelp32.h>
/************************************************************************/
/* 函数功能:根据当前路径将指定的文件启动 */
/************************************************************************/
void CTZY_CRH1_SystemView::OnShellExecuteEx( CString strPathName )
{
//====打开指定的exe文件
CString exeStr=strPathName; //设置要执行的应用程序路径
SHELLEXECUTEINFO Info;
memset (&Info, 0, sizeof(Info)) ;
Info.cbSize=sizeof (Info) ;
Info.lpVerb="open" ;
Info.lpFile=exeStr;
Info.lpParameters=NULL;
Info.fMask=SEE_MASK_NOCLOSEPROCESS ;
Info.nShow=SW_SHOWDEFAULT ;
if (! ShellExecuteEx (&Info))
{
MessageBox("执行程序操作失败!","信息提示",MB_OK);
}
}
/************************************************************************/
/* 函数功能:遍历进程、结束进程 */
/************************************************************************/
void CDemoDlg::Func()
{
HANDLE handle=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
PROCESSENTRY32* info=new PROCESSENTRY32;
info->dwSize=sizeof(PROCESSENTRY32);
int iProcessID; //===线程ID
CString str;
CString ProcessID,strProcessName;
while(Process32Next(handle,info)!=FALSE)
{
ProcessID.Format("%5d",info->th32ProcessID);
strProcessName.Format("%s",info->szExeFile);
//===关闭进程 --- 此处为测试关闭进程代码
HANDLE h=OpenProcess(PROCESS_ALL_ACCESS,TRUE,info->th32ProcessID);
TerminateProcess(h,0);
str = str + strProcessName + "\n";
}
MessageBox(str);
delete info;
CloseHandle(handle);
}