how to set windows service username and password through commandline

前端 未结 2 953
余生分开走
余生分开走 2020-12-24 01:29

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

sc query \"windows service name\"

The

相关标签:
2条回答
  • 2020-12-24 02:00

    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.
    0 讨论(0)
  • 2020-12-24 02:09

    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

    0 讨论(0)
提交回复
热议问题