fix(checks): os_service lifecycle bugfix

This commit is contained in:
Alessandro De Blasis 2022-09-21 09:26:47 +01:00
parent 3b9061ab5b
commit 7f7c320746
1 changed files with 8 additions and 9 deletions

View File

@ -16,20 +16,19 @@ var (
win windowsSystem = windowsOS{}
)
type OSServiceClient struct {
scHandle windows.Handle
}
type OSServiceClient struct{}
func NewOSServiceClient() (*OSServiceClient, error) {
scHandle, err := win.OpenSCManager(nil, nil, windows.SC_MANAGER_CONNECT)
if err != nil {
return nil, fmt.Errorf("error connecting to service manager: %w", err)
}
return &OSServiceClient{scHandle: scHandle}, nil
return &OSServiceClient{}, nil
}
func (client *OSServiceClient) Check(serviceName string) (err error) {
m := win.getWindowsSvcMgr(client.scHandle)
h, err := windows.OpenSCManager(nil, nil, windows.SC_MANAGER_CONNECT)
if err != nil {
return fmt.Errorf("failed to connect to Windows service manager: %w", err)
}
m := win.getWindowsSvcMgr(h)
defer m.Disconnect()
svcNamePtr, err := syscall.UTF16PtrFromString(serviceName)