From 6547573c4d81728a63f7679dbd663ad37c652694 Mon Sep 17 00:00:00 2001 From: Marco Pfatschbacher Date: Mon, 10 Oct 2022 23:56:32 +0200 Subject: [PATCH] Do not create windows services with an empty environment key (#343) Doing so will create services that are broken and will fail when started: `Error 87: The parameter is incorrect` This is a regression from https://github.com/kardianos/service/pull/312 --- service_windows.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/service_windows.go b/service_windows.go index 07ad04a..6b0333f 100644 --- a/service_windows.go +++ b/service_windows.go @@ -241,6 +241,10 @@ func lowPrivSvc(m *mgr.Mgr, name string) (*mgr.Service, error) { } func (ws *windowsService) setEnvironmentVariablesInRegistry() error { + if len(ws.EnvVars) == 0 { + return nil + } + k, _, err := registry.CreateKey( registry.LOCAL_MACHINE, `SYSTEM\CurrentControlSet\Services\`+ws.Name, registry.QUERY_VALUE|registry.SET_VALUE|registry.CREATE_SUB_KEY)