1

I've tried to create a executable as a windows service using golang based on example provided in https://github.com/golang/sys/tree/master/windows/svc/example

I intended to create auto start service with executable specific command line argument 'init'

So whenever service get started executable should perform init operation. Following go code snippet is looks like this.

service control code snippet

based on the documentation,

  1. I added command line argument along with binarypath as mentioned in this config https://pkg.go.dev/golang.org/x/sys/windows/svc/mgr#Config

  2. I added commandline argument in CreateService method. https://pkg.go.dev/golang.org/x/sys/windows/svc/mgr#Mgr.CreateService

  3. Tried with Execute args. https://pkg.go.dev/golang.org/x/sys/windows/svc/mgr#Service.Start

But start parameter is not properly added in windows service and executable is nor running as expected.

In created windows service I'm able to see init is added along with executable name, but it is not added in start parameter as well as whenever service is started it is expected to write some log in file, that is also not happening.

Windows Service

Can anyone let me know if this configurations are valid ? If not suggest your thoughts. Thanks.

0

The following is supposed to be a comment, but I do not posses the permission to do so, thus writing it as an answer.

source says 'CreateService installs new service name on the system. The service will be executed by running exepath binary. Use config c to specify service parameters. Any args will be passed as command-line arguments when the service is started; these arguments are distinct from the arguments passed to Service.Start or via the "Start parameters" field in the service's Properties dialog box.'

1
  • Please provide additional details in your answer. As it's currently written, it's hard to understand your solution.
    – Community Bot
    Sep 3 at 4:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.