Skip to content

servy-cli stop fails when WMI is unavailable — uses WMI internally via ServiceHelper.GetRunningServices #48

@Christophe-Rogiers

Description

@Christophe-Rogiers

Environment: Windows 10/11 Enterprise, PowerShell 5.1, Servy CLI (portable mode)

Issue: servy-cli.exe stop --name= --quiet fails with exit code 1 after 75s timeout when WMI is in "Shutting down" state. sc.exe stop succeeds immediately on the same service.

Root cause: Before executing the stop command, the CLI calls ResourceHelper.CopyEmbeddedResource which calls ServiceHelper.GetRunningServyCLIServices() → GetRunningServices() → WMI (System.Management.ManagementObjectCollection). When WMI is unavailable, this throws ManagementException: Shutting down.

Stack trace:

System.InvalidOperationException: Failed to query services for Servy.Service.CLI.exe: Shutting down
---> System.Management.ManagementException: Shutting down
at System.Management.ManagementObjectCollection.ManagementObjectEnumerator.MoveNext()
at Servy.Core.Helpers.ServiceHelper.GetRunningServices(String wrapperExe)
at Servy.Core.Helpers.ServiceHelper.GetRunningServyCLIServices()
at Servy.Core.Helpers.ResourceHelper.CopyEmbeddedResource(...)
Impact: We chose Servy specifically to avoid WMI dependency in our deployment (800K+ machines). On machines where WMI is unstable during deployment, every stop call loses ~75 seconds before falling back to sc.exe.

Suggestion: Could ServiceHelper.GetRunningServices use the Windows Service Control Manager API (like sc.exe query) instead of WMI? Or at minimum, skip the CopyEmbeddedResource step when the CLI is run in portable/--quiet mode, since the embedded resource is already present on disk.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions