開啟/關閉/遍歷程序的類 代碼(C++)
類包含4個函數, 啟動程序, 遍歷所有進程, 關閉程序, 遍歷進程依賴的動態鏈接庫.
示例: Image.exe是預先生成的可執行程序(exe), 啟動程序, 間隔5秒, 關閉程序.
使用方法參加測試程序.
代碼:
/*
* process.h
*
* Created on: 2014.06.08
* Author: Spike
*/
/*vs 2012*/
#ifndef TRAVERSEPROCESSMODEL_H
#define TRAVERSEPROCESSMODEL_H
#include
#include
#include
#include
測試代碼:
/*
* main.cpp
*
* Created on: 2014.06.08
* Author: Spike
*/
/*vs 2012*/
#include process.h
using namespace std;
int main(void)
{
Process tpm;
const std::string name = D:/Test/Image.exe;
const std::string programme = Image.exe;
if (!tpm.startProcess(name)) {
cout << Start Processe Error! << endl;
}
Sleep(5000);
if(!tpm.terminateProcess(programme)){
cout << Terminate Process Error! << endl;
}
return 0;
}
輸出: