WbemObject.Terminate失败原因

WbemObject.Terminate failure reason

至于现在,我正在改进我的 Inno Setup 安装程序中的日志记录,所以如果消费者遇到某种错误,我可以很容易地看出哪里出了问题。

作为安装操作之一,我终止了应用程序进程,如果它是运行,以优雅地覆盖文件。为了终止应用程序,我使用了问题 Inno Setup Kill a running process - getting WbemObject and calling WbemObject.Terminate.

中描述的方法

至于现在,我想跟踪一下,如果Terminate成功了。从我的测试中,我发现它实际上是 returns 布尔值,表示应用程序是否已成功终止。但如果它失败了,它只是 returns "false"。而且我想知道更详细的原因。

那么,有没有办法得到 WbemObject.Terminate 的实际失败原因?

你拥有的不是 WbemObject,而是 Win32_Process object

Win32_Process.Terminate method 执行 return uint32(Pascal 中的 Cardinal),而不是 Boolean

Returns a value of 0 (zero) if the process was successfully terminated, and any other number to indicate an error. For additional error codes, see WMI Error Constants or WbemErrorEnum. For general HRESULT values, see System Error Codes.

Successful completion (0)
Access denied (2)
Insufficient privilege (3)
Unknown failure (8)
Path not found (9)
Invalid parameter (21)
Other (22–4294967295)