how to set windows service username and password through commandline

Using sc command we can query, start , stop windows services. For ex:

sc query "windows service name"

The sc config command changes the configuration of the service, but I don't know how to use it.

Could someone tell me how we can set the username and password for any windows service?

Answers


This works:

sc.exe config "[servicename]" obj= "[.\username]" password= "[password]"

Where each of the [bracketed] items are replaced with the true arguments. (Keep the quotes, but don't keep the brackets.)

Just keep in mind that:

  • The spacing in the above example matters. obj= "foo" is correct; obj="foo" is not.
  • '.' is an alias to the local machine, you can specify a domain there (or your local computer name) if you wish.
  • Passwords aren't validated until the service is started
  • Quote your parameters, as above. You can sometimes get by without quotes, but good luck.

In PowerShell, the "sc" command is an alias for the Set-Content cmdlet. You can workaround this using the following syntax:

sc.exe config Service obj= user password= pass

Specyfying the .exe extension, PowerShell bypasses the alias lookup.

HTH


Need Your Help

Should I always make my java-code thread-safe, or for performance-reasons do it only when needed?

java multithreading performance concurrency thread-safety

If I create classes, that are used at the moment only in a single thread, should I make them thread-safe, even if I don't need that at the moment? It could be happen, that I later use this class in