hetptis
hetptis

Reputation: 806

Access Denied when trying to run WSL bash.exe as system user (via a service)

I want to manage a service running inside WSL via a wrapper service running on Windows. But when I try to run the wrapper Windows service (which by default run as the "System" user, it throws an "Access Denied" error.

Same service when run as a normal Admin user works fine.

Does anyone know of a way to work around this and make it possible to run bash.exe as the "System" user? Or is that way by design and should be avoided?

Note: I use the following go code to run the WSL service. (I build this command into an exe and install it on Windows as a service using winsw)

exec.Command("bash.exe", "-c", "sudo /bin/bash service my-linux-service start")

Upvotes: 2

Views: 1751

Answers (1)

tilak
tilak

Reputation: 86

Ran into the same issue today,
I'm using NSSM to setup Windows services and I manage to sort things out by setting the objectName to the current user for this service.
Now my service is executed by a user that can access WSL :

nssm set <servicename> ObjectName <username> <password>

Note: <username> should exactly be the output of whoami.exe

See NSSM Documentation for more info.

Upvotes: 2

Related Questions