我要实现利用这个小程序来检测test.exe是否已经运行,没有运行的话,启动test.exe.
我的代码如下:
procedure TForm1.Timer1Timer(Sender: TObject);
var
hd:Thandle;
mypath,z:string;
z: string;
begin
MyPath:=ExtractFilePath(ParamStr(0));
hd:=findwindow(nil,'测试');
if hd=0 then
begin
z:=mypath+'test.exe';
winexec(pchar(z),SW_SHOW);
end;
end;执行第一次是正常的,但test.exe关闭之后,就不再重新启动了(这段代码在Timer里面),请高手指点,还有什么好办法没有?
我的代码如下:
procedure TForm1.Timer1Timer(Sender: TObject);
var
hd:Thandle;
mypath,z:string;
z: string;
begin
MyPath:=ExtractFilePath(ParamStr(0));
hd:=findwindow(nil,'测试');
if hd=0 then
begin
z:=mypath+'test.exe';
winexec(pchar(z),SW_SHOW);
end;
end;执行第一次是正常的,但test.exe关闭之后,就不再重新启动了(这段代码在Timer里面),请高手指点,还有什么好办法没有?
将SW_SHOW改成SW_NORMAL
var
hd: Thandle;
begin
hd := findwindow(nil, '计算器');
if hd=0 then
begin
winexec(PChar('calc'), SW_SHOW);
end;
end;
begin
z:=mypath+'test.exe';
winexec(pchar(z),SW_SHOW);
end
else showmessage('a')看能不能showmessage,好确定问题出在hd>0还是winexec没调用成功