-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get-WmiObject - Invalid class "Win32_Service" - Workaround
- Loading branch information
Showing
2 changed files
with
26 additions
and
8 deletions.
There are no files selected for viewing
17 changes: 13 additions & 4 deletions
17
dev-tools/packaging/templates/windows/install-service.ps1.tmpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 13 additions & 4 deletions
17
dev-tools/packaging/templates/windows/uninstall-service.ps1.tmpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,16 @@ | ||
# Delete and stop the service if it already exists. | ||
if (Get-Service {{.BeatName}} -ErrorAction SilentlyContinue) { | ||
$service = Get-WmiObject -Class Win32_Service -Filter "name='{{.BeatName}}'" | ||
$service.StopService() | ||
Start-Sleep -s 1 | ||
$service.delete() | ||
try { | ||
$service = Get-WmiObject -Class Win32_Service -Filter "name='{{.BeatName}}'" | ||
$service.StopService() | ||
(Get-Service {{.BeatName}}).WaitForStatus('Stopped') | ||
Start-Sleep -s 1 | ||
$service.delete() | ||
} | ||
catch { | ||
Stop-Service {{.BeatName}} | ||
(Get-Service {{.BeatName}}).WaitForStatus('Stopped') | ||
Start-Sleep -s 1 | ||
sc.exe delete {{.BeatName}} | ||
} | ||
} |