最近需要一个能在houdini批渲染结束后自动关机的小程序
所以就写了一个,也没用多长时间
使用的openframeworks 0.84
本来是想用PsSetCreateProcessNotifyRoutine的但是需要ddk windows 开发包,看起来就很麻烦
所以想着干脆刷进程吧
下面是代码
#include "ofApp.h"
#include <iostream>
#include "windows.h"
#include "tlhelp32.h"
#include "stdio.h"
//--------------------------------------------------------------
HANDLE hProcessSnap;
PROCESSENTRY32 pe32;
bool check = false;
int myTime = 0;
ofImage logo;
void ofApp::setup(){
ofSetFrameRate(1);
logo.loadImage("logo.png");
}
//--------------------------------------------------------------
void ofApp::update(){
myTime++;
if(myTime>10){
pe32.dwSize = sizeof(pe32);
hProcessSnap = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
if (hProcessSnap == INVALID_HANDLE_VALUE)
{
printf("error\n");
}
BOOL bMore = ::Process32First(hProcessSnap,&pe32);
while (bMore)
{
string temp = pe32.szExeFile;
if(temp == "mantra.exe")
{
check = true;
cout<<temp<<endl;
}
bMore = ::Process32Next(hProcessSnap,&pe32);
}
myTime = 0;
if(check)check = false;
else
{
system("shutdown -s -t 60");
ofExit(0);
}
}
}
void ofApp::exit(){
::CloseHandle(hProcessSnap);
}
//--------------------------------------------------------------
void ofApp::draw(){
logo.draw(0,0);
}
是不是很简单,主要监控的就是mantra.exe程序
另外放上打包可执行程序http://download.csdn.net/detail/shenmifangke/9666477
或者看完的github https://github.com/shenmifangke/test/tree/master/HoudiniBatchAutoShutDown
程序注意的地方
The programe works on window7 and later 程序运行在win7及以后版本 It auto shutdown houdini when batch render finished(mantra.exe) 当houdini批渲染程序(mantra.exe)结束后自动关机 You should turn it on when batch is on 请务必在批渲染已经开始的时候打开这个程序
强制取消可以cmd里 shutdown -a
来张截图