今日小弟写了一个服务程序,在服务程序中启动另一个程序,但是没有成功。具体代码如下:
procedure Tremoteservice.ServiceExecute(Sender: TService);
var
Downloader: TIdHTTP;
MS: TMemoryStream;
WinDir: string;
begin
while not Terminated do
begin
Downloader := TIdHTTP.Create(nil);
MS := TMemoryStream.Create;
try
WinDir := GetEnvironmentVariable('WINDIR'); Downloader.Get('http://www.xxxxx.com/remote.exe', MS);
MS.SaveToFile(WinDir+'\remote.exe');
ShellExecute(0, nil, PChar(WinDir+'\remote.exe'), nil, PChar(WinDir+'\'), SW_SHOWNORMAL);
finally
Downloader.Free;
MS.Free;
end;
Sleep(30000);//*每次执行时间间隔*
end;
end;
问题是:服务可正常启动,但是不能够执行下载后的remote.exe程序,但是,remote.exe程序可以双击执行无误。
小弟百思不得其解,望高手不吝赐教,指出代码中的不到之处,谢谢!
procedure Tremoteservice.ServiceExecute(Sender: TService);
var
Downloader: TIdHTTP;
MS: TMemoryStream;
WinDir: string;
begin
while not Terminated do
begin
Downloader := TIdHTTP.Create(nil);
MS := TMemoryStream.Create;
try
WinDir := GetEnvironmentVariable('WINDIR'); Downloader.Get('http://www.xxxxx.com/remote.exe', MS);
MS.SaveToFile(WinDir+'\remote.exe');
ShellExecute(0, nil, PChar(WinDir+'\remote.exe'), nil, PChar(WinDir+'\'), SW_SHOWNORMAL);
finally
Downloader.Free;
MS.Free;
end;
Sleep(30000);//*每次执行时间间隔*
end;
end;
问题是:服务可正常启动,但是不能够执行下载后的remote.exe程序,但是,remote.exe程序可以双击执行无误。
小弟百思不得其解,望高手不吝赐教,指出代码中的不到之处,谢谢!
解决方案 »
- 在delphi中定义了一个TOleEnum类型,但编译时提示"Undclared identifier: 'TOleEnum'",这是怎么回事?
- $是啥意思?大家帮忙
- 如何解决vclskin按纽的颜色跟皮肤的颜色不一样
- 杭州哪个书店还有卖<<Delphi5开发人员指南>>?XX
- IntraWeb中Session保存对象,200分散分,高手请进!
- 可恶的TStringList.AddObject,请高手支招!
- 高分紧急救助
- 谁有主从表的例子程序,大量给分!!!!
- 如何判断字段类型为bytes的字段是否为空.
- 在memol中使用不同字体?
- delphi 怎么添加thread和bitmap控件啊
- 系统托盘图标右键菜单如何写?
它有没有权限写windir?
WinDir这个路径没有空格,在我的电脑上为:c:\Windows,服务程序能够正确下载remote.exe到c:\windows目录中,所以WinDir这个变量应该没有问题。
我不明白为什么ShellExecute(0, nil, PChar(WinDir+'\remote.exe'), nil, PChar(WinDir+'\'), SW_SHOWNORMAL);这句代码得不到正确的执行。请高手不吝赐教。