I'm working with a VB Script file written by someone else that uses Windows Management Instrumentation (WMI) calls to check on the status of several Windows Services. This script runs every few minutes on set schedule. I need to upgrade/replace the .exe for those services.
I stop the VB Script, stop the services, and uninstall the services so they no longer appear in the Services panel (services.msc). Unfortunately, WMI (wmiprvse.exe) still has a handle on the service .exe files. I can release the handle by rebooting the system, but I want to avoid that if at all possible so this can be a completely scripted/automated upgrade.
Is there a way I can force WMI to release it's handle on the .exe? Please keep in mind I'm new to working with WMI.
I'm also looking for a solution to this problem. Would also like to understand why wmiprsve has handles on some of my service executables but not on others.
The workaround I'm using is to kill the wmiprvse process. You can use the SysInternals command line tools (pslist, pskill) to automate getting the process id and performing the kill.
You can simply restart the WMI service (winmgmt) to force it to release your files. If your service isn't registered when WMI starts it won't put a lock on the files.
Stop service, uninstall service, restart WMI, replace files, start service.