<p>The following is supposed to be a comment, but I do not posses the permission to do so, thus writing it as an answer.</p>
<p><a href="https://cs.opensource.google/go/x/sys/+/f475640d:windows/svc/mgr/mgr.go;l=116" rel="nofollow noreferrer">source</a> 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.
<strong>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 &quot;Start
parameters&quot; field in the service's Properties dialog box.</strong>'</p>

CC BY-SA 4.0
2021-09-03T04:56:43.637Z
Please provide additional details in your answer. As it's currently written, it's hard to understand your solution.
Community
CC BY-SA 4.0
2021-09-03T04:44:31.280Z
2021-09-04T14:59:04.250Z
2021-09-04T14:59:04.250Z
BluePie
<p>I've tried to create a executable as a windows service using golang based on example provided in <a href="https://github.com/golang/sys/tree/master/windows/svc/example" rel="nofollow noreferrer">https://github.com/golang/sys/tree/master/windows/svc/example</a></p>
<p>I intended to create auto start service with executable specific command line argument 'init'</p>
<p>So whenever service get started executable should perform init operation. Following go code snippet is looks like this.</p>
<p><a href="https://i.sstatic.net/bMomg.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/bMomg.png" alt="service control code snippet" /></a></p>
<p>based on the documentation,</p>
<ol>
<li><p>I added command line argument along with binarypath as mentioned in this config <a href="https://pkg.go.dev/golang.org/x/sys/windows/svc/mgr#Config" rel="nofollow noreferrer">https://pkg.go.dev/golang.org/x/sys/windows/svc/mgr#Config</a></p>
</li>
<li><p>I added commandline argument in CreateService method. <a href="https://pkg.go.dev/golang.org/x/sys/windows/svc/mgr#Mgr.CreateService" rel="nofollow noreferrer">https://pkg.go.dev/golang.org/x/sys/windows/svc/mgr#Mgr.CreateService</a></p>
</li>
<li><p>Tried with Execute args. <a href="https://pkg.go.dev/golang.org/x/sys/windows/svc/mgr#Service.Start" rel="nofollow noreferrer">https://pkg.go.dev/golang.org/x/sys/windows/svc/mgr#Service.Start</a></p>
</li>
</ol>
<p>But start parameter is not properly added in windows service and executable is nor running as expected.</p>
<p>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.</p>
<p><a href="https://i.sstatic.net/Me8Vk.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Me8Vk.png" alt="Windows Service" /></a></p>
<p>Can anyone let me know if this configurations are valid ? If not suggest your thoughts. Thanks.</p>

<windows><go>
Failed to start windows service with Start Parameter in golang
imaheshwaran s
# Failed to start windows service with Start Parameter in golang

(Asked by: username_0 on 2021-09-02)

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](https://i.sstatic.net/bMomg.png)](https://i.sstatic.net/bMomg.png)

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](https://i.sstatic.net/Me8Vk.png)](https://i.sstatic.net/Me8Vk.png)

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

**Tags:** windows, go


---

## 1 answers

### Answer by username_1 on 2021-09-03. Score: 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](https://cs.opensource.google/go/x/sys/+/f475640d:windows/svc/mgr/mgr.go;l=116) 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.**'

> **Comments:**
> **username_2**: Please provide additional details in your answer. As it's currently written, it's hard to understand your solution.  

---

