How to set windows service username and password through commandline

sc.exe config “servicename” obj= “.\username” password= “passwd”

  1. Mind the spaces in the syntax
  2. “.” is an alias to the local machine but can be replaced by a domain name
  3. Passwords are only validated after a restart of the service.