Merge pull request #863 from jsturtevant/fix-service-identification

use IsWindowsService to detect if running as service
This commit is contained in:
Calle Pettersson
2021-11-05 18:47:18 +01:00
committed by GitHub

View File

@@ -1,3 +1,4 @@
//go:build windows
// +build windows // +build windows
package main package main
@@ -324,13 +325,13 @@ func main() {
initWbem() initWbem()
isInteractive, err := svc.IsAnInteractiveSession() isService, err := svc.IsWindowsService()
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
stopCh := make(chan bool) stopCh := make(chan bool)
if !isInteractive { if isService {
go func() { go func() {
err = svc.Run(serviceName, &windowsExporterService{stopCh: stopCh}) err = svc.Run(serviceName, &windowsExporterService{stopCh: stopCh})
if err != nil { if err != nil {