Msi不等待服务完全停止再返回

时间:2018-11-13 21:59:56

标签: windows-installer installshield

我使用InstallShield构建了一个Msi。

MSI用于一个Windows服务。安装程序的服务事件设置为等待事件完成

[Install Start, Install Stop, Install Delete, Uninstall Stop, Uninstall Delete]

但是,在升级(REINSTALL=ALL REINSTALLMODE=vomus)期间,我总是在一台低功耗测试VM上收到提示重新启动的提示。

因此,我继续进行详细日志记录,以了解发生了什么情况。

一些关键日志条目如下:

MSI (s) (8C:E0) [15:20:59:264]: RESTART MANAGER: Detected that the service {my service} will be stopped due to a service control action authored in the package before the files are updated. So, we will not attempt to stop this service using Restart Manager
MSI (s) (8C:E0) [15:20:59:264]: Note: 1: 2727 2:  

由于该服务正在运行,因此应有的期望,一旦服务停止,一切都应解锁

MSI (s) (8C:E0) [15:21:00:483]: Doing action: StopServices
Action 15:21:00: StopServices. Stopping services
Action start 15:21:00: StopServices.
StopServices: Service: Stopping services
Action ended 15:21:00: StopServices. Return value 1.
MSI (s) (8C:E0) [15:21:00:483]: Doing action: DeleteServices
Action 15:21:00: DeleteServices. Deleting services
Action start 15:21:00: DeleteServices.
DeleteServices: Service: Deleting services
Action ended 15:21:00: DeleteServices. Return value 1.

服务在15:21:00停止并删除(时间戳表明该服务已在1秒内停止。但是,通过服务管理控制台完成操作后,缓慢的VM最多需要10秒才能完全停止该服务)

MSI (s) (8C:E0) [15:21:02:232]: Executing op: FileCopy(SourceName={removed},SourceCabKey={removed},DestName={removed},Attributes=16384,FileSize=17488,PerTick=65536,,VerifyMedia=1,,,,,CheckCRC=0,Version=3.6.12.442,Language=0,InstallMode=126091264,,,,,,,)
MSI (s) (8C:E0) [15:21:02:232]: File: C:\Program Files (x86)\{my exe};  Overwrite;  Won't patch;    Existing file is a lower version
MSI (s) (8C:E0) [15:21:02:232]: Source for file '{removed}' is compressed
InstallFiles: File: {my exe},  Directory: C:\Program Files (x86)\{removed},  Size: 17488
MSI (s) (8C:E0) [15:21:02:232]: Re-applying security from existing file.
Info 1603. The file C:\Program Files (x86)\{my exe} is being held in use.  Close that application and retry.
MSI (s) (8C:E0) [15:21:07:700]: Verifying accessibility of file: {my exe}
MSI (s) (8C:E0) [15:21:07:700]: Note: 1: 2318 2:  
MSI (s) (8C:E0) [15:21:07:700]: Note: 1: 2318 2:  

由于服务进程正在运行,因此文件复制操作在15:21:07失败。

所以我决定我将尝试先停止服务,以确保它在达到复制文件操作之前已完全停止

我在调用

InstallValidate操作之前添加了自定义事件
sc stop {service name}

使其同步运行,但忽略退出代码

MSI (s) (0C:40) [15:30:53:066]: Doing action: AttemptStopService
Action 15:30:53: AttemptStopService. 
Action start 15:30:53: AttemptStopService.
Action ended 15:30:53: AttemptStopService. Return value 1.
MSI (s) (0C:40) [15:30:53:113]: Doing action: InstallValidate
Action 15:30:53: InstallValidate. Validating install
Action start 15:30:53: InstallValidate.

但这会导致“安装程序必须更新在系统运行时无法更新的文件或服务。如果选择继续,则将需要重新启动....”。当显示弹出窗口时,我检查了任务管理器并且该过程消失了,服务停止了。

同样,这意味着sc.exe在返回调用方之前没有等待进程完全终止。

我错过了什么吗?还是设计使然?在安装程序或service.exe方面,我可以做些什么来防止这种情况发生?

更新
我添加了另一个自定义操作,该操作将弹出一个cmd窗口,该窗口列出了与我的服务关联的当前正在运行的进程,以查看该操作是否确实没有等待进程停止。

cmd.exe /k tasklist /FI "Services eq my service name"

操作被放置在RemoveFiles之前(在InstallFiles之前一点),这里是新的日志

MSI (s) (A8:F8) [10:56:42:725]: Doing action: StopServices
Action 10:56:42: StopServices. Stopping services
Action start 10:56:42: StopServices.
Action ended 10:56:42: StopServices. Return value 1.
MSI (s) (A8:F8) [10:56:42:725]: Doing action: DeleteServices
Action 10:56:42: DeleteServices. Deleting services
Action start 10:56:42: DeleteServices.
Action ended 10:56:42: DeleteServices. Return value 1.

...

MSI (s) (A8:F8) [10:56:42:757]: Doing action: Test
Action 10:56:42: Test. 
Action start 10:56:42: Test.
CustomAction Test returned actual error code -1073741510 but will be translated to success due to continue marking

在CMD窗口中,即使先前的停止服务操作应已停止并删除,我仍可以清楚地看到该进程仍在运行。

还在CMD窗口上提供了1分钟以上的时间,并且该服务仍在运行,进程仍在运行。因此停止服务操作基本上根本不起作用。

0 个答案:

没有答案