Skip to content

Commit

Permalink
Get-WmiObject - Invalid class "Win32_Service" - Workaround (#33322)
Browse files Browse the repository at this point in the history
* Get-WmiObject - Invalid class "Win32_Service" - Workaround

* try/catch replace + changelog documentation

* Changelog fix

Co-authored-by: Lee E. Hinman <lee.e.hinman@elastic.co>
Co-authored-by: Craig MacKenzie <craig.mackenzie@elastic.co>
  • Loading branch information
3 people authored Nov 3, 2022
1 parent 82cb594 commit 4e58e31
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ https://github.com/elastic/beats/compare/v8.2.0\...main[Check the HEAD diff]
- Fix concurrent map writes when system/process code called from reporter code {pull}32491[32491]
- Fix in AWS related services initialisation relying on custom endpoint resolver. {issue}32888[32888] {pull}32921[32921]
- Keep `orchestrator.cluster.name` if `kubeconfig` is not returned in GKE metadata. {pull}33418[33418]
- Fix Windows service install/uninstall when Win32_Service returns error, add logic to wait until the Windows Service is stopped before proceeding. {pull}33322[33322]
- Support for multiline zookeeper logs {issue}2496[2496]

*Auditbeat*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# 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()
Stop-Service {{.BeatName}}
(Get-Service {{.BeatName}}).WaitForStatus('Stopped')
Start-Sleep -s 1
$service.delete()
sc.exe delete {{.BeatName}}
}

$workdir = Split-Path $MyInvocation.MyCommand.Path
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# 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()
Stop-Service {{.BeatName}}
(Get-Service {{.BeatName}}).WaitForStatus('Stopped')
Start-Sleep -s 1
$service.delete()
sc.exe delete {{.BeatName}}
}

0 comments on commit 4e58e31

Please sign in to comment.