use IsWindowsService to detect if running as service

Signed-off-by: James Sturtevant <jstur@microsoft.com>
This commit is contained in:
James Sturtevant
2021-11-05 10:12:02 -07:00
parent 947d8473e0
commit a6ea021468

View File

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