Search code examples
gowindows-services

How to set a login user account for a windows service written in Golang?


I use the package "https://pkg.go.dev/github.com/kardianos/service" to run an application written in Go as a Windows service.

I set the following attributes in service.Config:

Username: "myusername"
Option: service.KeyValue{"password": "mypassword"}

When I then install the program, I get the following error: The account name is invalid or does not exist, or the password is invalid for the account name specified.

How should I set attributes of service.Config to make the service run properly with specified the credentials when installed?


Solution

  • I just found out the solution myself.

    Username:`DESKTOP-XXXXXX\myAcount`
    Option: service.KeyValue{"password": "mypassword"}