Installing a windows service on remote machine using given username

好久不见. 提交于 2019-12-17 17:48:31

问题


What is the best way to install a windows service written in C# (in the standard way) on a remote machine, where I need to provide the username and password it should run as?

I am going to run it from MSBuild as part of integration tests.

EDIT: I don't have an msi and I don't want to create one.


回答1:


You can use the SC command.

sc.exe \\remotecomputer create newservice binpath= C:\Windows\System32\Newserv.exe start= auto obj= DOMAIN\username password= pwd

(Note the spaces after the equals signs are important)

Creates a service entry in the registry and Service Database.
SYNTAX: 
sc create [service name] [binPath= ] <option1> <option2>...
CREATE OPTIONS:
NOTE: The option name includes the equal sign.
 type= <own|share|interact|kernel|filesys|rec>
       (default = own)
 start= <boot|system|auto|demand|disabled>
       (default = demand)
 error= <normal|severe|critical|ignore>
       (default = normal)
 binPath= <BinaryPathName>
 group= <LoadOrderGroup>
 tag= <yes|no>
 depend= <Dependencies(separated by / (forward slash))>
 obj= <AccountName|ObjectName>
       (default = LocalSystem)
 DisplayName= <display name>
 password= <password> 



回答2:


Installutil called from WMI invoked from Powershell is one way to go.




回答3:


We used to use PsExec to do everything on remote machine. At this time I saw naother solution called PowerShell Remoting, but haven't tried myself.




回答4:


It might be worth you checking out a utility I wrote which lets you install/uninstall/start/stop windows services on a local or remote machine. If you have a feature you need added let me know (comment/github issues or PM and I'll happily oblige).

ServiceConfigurator on GitHub

As @Raj More suggested, it uses WMI invoked from .NET.



来源:https://stackoverflow.com/questions/1159012/installing-a-windows-service-on-remote-machine-using-given-username

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!