我使用PrepareToInstall事件来停止和删除服务。这很好,没有抛出错误。
然而,有时似乎出现了时间问题,因为有时InnoSetup告诉我,“涛动维护服务”仍然在运行,并询问是否应该关闭它。
我认为如果API从函数返回以关闭和删除服务,那么应用程序就应该已经消失了。
有没有人认为我有任何错误,或者有什么建议给我?
谢谢!
function PrepareToInstall(var NeedsRestart: Boolean): String;
begin
//MsgBox('ssInstall.', mbInformation, MB_OK);
if IsServiceInstalled('oscmaintenanceservice') then
BEGIN
//MsgBox('ssInstall: Service is installed.', mbInformation, MB_OK);
if IsServiceRunning('oscmaintenanceservice') then
BEGIN
//MsgBox('ssInstall: Service is running.', mbInformation, MB_OK);
if not StopService('oscmaintenanceservice') then
BEGIN
MsgBox('ssInstall: Couldnt stop service.', mbInformation, MB_OK);
END
else
BEGIN
//MsgBox('ssInstall: Service was stopped.', mbInformation, MB_OK);
END;
END
else
BEGIN
MsgBox('ssInstall: Service not running.', mbInformation, MB_OK);
END;
if not RemoveService('oscmaintenanceservice') then
BEGIN
MsgBox('ssInstall: Couldnt remove service.', mbInformation, MB_OK);
END
else
BEGIN
//MsgBox('ssInstall: Service was removed', mbInformation, MB_OK);
END;
END
else
BEGIN
MsgBox('ssInstall: Service not installed.', mbInformation, MB_OK);
END;
END;发布于 2016-05-24 17:49:48
看来Windows需要一点时间来识别已删除的服务。
在PrepareToInstall中的停止和删除函数之后,我增加了睡眠(1000),从那时起,它工作得很好。
https://stackoverflow.com/questions/37412927
复制相似问题