OnStart里,建立线程,
var //全局变量
hList : array [0..1] of THandle;
线程程序
var
n : integer;
PID : DWORD;
begin
hList[0] := CreateEvent(NIL, False , False , NIL);
//if hList[0]=0 then错误处理
while Not Terminated do begin
PID := GetProcessID('进程.Exe');//这个函数得自己实现
if PID=0 then begin
//启动程序
Continue;
end;
hList[1] := OpenProcess(PROCESS_ALL_ACCESS,False,PID);
if hList[1]=0 then begin
//错误处理
end;
n := WaitForMultipleObjects(2, @hList , False , DWORD(-1));
CloseHandle(hList[1]);
if n=AIT_OBJECT_0+1 then begin
//重新启动程序
Continue;
end;
if n=WAIT_OBJECT_0 then Break;
//n=其他 错误处理
end;
CloseHandle(hList[0]);
FreeOnTerminate := True;
end;OnStop时
begin
ThreadObject.Terminate;
SetEvent(hList[0]);
end;
var //全局变量
hList : array [0..1] of THandle;
线程程序
var
n : integer;
PID : DWORD;
begin
hList[0] := CreateEvent(NIL, False , False , NIL);
//if hList[0]=0 then错误处理
while Not Terminated do begin
PID := GetProcessID('进程.Exe');//这个函数得自己实现
if PID=0 then begin
//启动程序
Continue;
end;
hList[1] := OpenProcess(PROCESS_ALL_ACCESS,False,PID);
if hList[1]=0 then begin
//错误处理
end;
n := WaitForMultipleObjects(2, @hList , False , DWORD(-1));
CloseHandle(hList[1]);
if n=AIT_OBJECT_0+1 then begin
//重新启动程序
Continue;
end;
if n=WAIT_OBJECT_0 then Break;
//n=其他 错误处理
end;
CloseHandle(hList[0]);
FreeOnTerminate := True;
end;OnStop时
begin
ThreadObject.Terminate;
SetEvent(hList[0]);
end;
解决方案 »
- fastreport4预览时显示的数据都是第一条的数据
- HWND句柄怎么用?
- 两个应用程序如何公用一个SocketClient,或者其他方式 工发工具为DELPHI6.0
- 远程采用何种技术为好?????????
- 如何使用odac控件获取oracle数据库中的所有表的名称!或者如何获取数据库中所有表名?
- 如何在WIN2000下正确显示XP的高彩色图标?
- 一个与时间有关的问题
- 第一次操作报表可以正常显示,,进行另一次选择操作的时候,就没有数据显示出来了,怎么回事?在线等待!!!!急
- 人生之路如何走,我去拿家单位比较好?
- 我的程序中调用了另外一个程序的可执行文件,请问我怎么在推出我的程序时,同时把那个程序也关掉那???谢谢帮忙!!
- 刚从VB转delphi,请问delphi有没有类似VB的Shell函数 [运行外部程序并返回PID]
- 谁会使用DELPHI编写驱动级的程序出来聊聊吧
你再写一个后台程序监控这个后台进程就行了,不一定要服务
现在唯一拿不准的是,如果用户不是以administrator登录的话,会不会影响这个服务打开程序?好像在win7里似乎有权限之类的东西。