Used to monitor another process and automatically reboot the process when it is turned off.
Can be implemented using scripting, such as VBS or BAT. The following program uses C + + implementation: To monitor the target program HTServer.exe and run the target program if the target program is not running.
The code is as follows:
[CPP] View plain copy print? htservermonitor.cpp : defines the entry point for the console application. // #include <iostream> #include <windows.h> #include <stdio.h> #include <tchar.h> using namespace std; Int _tmain (Int argc, _tchar *argv[]) { STARTUPINFO si; process_information pi; //process information: zeromemory (&si, sizeof (SI)); si.cb = sizeof (SI); zeromemory (&pi, sizeof (PI)); do{ // Create a subprocess to determine whether to execute success &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;IF (! CreateProcess ( null, "cmd /c c:\\users\\hk\\desktop\\htversions\\htserver\\ Htservereditversion4.2\\debug\\htserver.exe ", Null,null,false,0,null,null,&si,&pi) { cout << "Create process failed ..." << getlasterror () << endl; system ("pause"); //for testing return 0; } //Process Execution successful, printing process information cout << "The following are child process information:" << endl; cout << "Process id pi.dwprocessid: " << pi.dwProcessId << endl; cout << Thread ID pi.dwThreadID : " << pi.dwThreadId << endl; // waiting to know the subprocess exits ... waitforsingleobject ( pi.hprocess, infinite)//detection process stop The //waitforsingleobject () function checks the state of the object and waits until timeout if it is indeterminate //child process Exit cout << "Subprocess has exited ..." << endl; //shutdown process and handle closehandle (pi.hprocess); &NBSP;&NBSP;&NBSP;&NBsp; closehandle (pi.hthread); //system ("pause")//Wait }while (true) after completion;//If the process is rolled out, execute the method again exit (0); return 0; } above code from: http://flylynne.iteye.com/blog/580751
There is no problem with compiling in VC6, but when you use VS08, you will get an error:
Error C2664: ' CREATEPROCESSW ': cannot convert parameter 2 from ' const char[15 ' to ' lpwstr ';
Workaround: Open the property-> the general-> character set to "not set".