PrepareToInstall 计时

PrepareToInstall timing

我正在使用 PrepareToInstall 事件来停止和删除服务。 这工作正常,没有抛出任何错误。

但是有时似乎存在时间问题,因为有时 InnoSetup 告诉我 'oscmaintenanceservice' 仍然是 运行 并询问是否应该关闭它。

我想如果API returns 从函数中关闭并删除服务,应用程序应该已经消失了。

有没有人看到我这边有什么错误或者对我有什么建议?

谢谢!

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;

似乎 Windows 需要一点时间来识别该服务已被删除。

我在 PrepareToInstall 的停止和删除功能后添加了 sleep(1000),从那以后它工作正常。