使用给定的用户名在远程机器上安装windows服务
问题描述:
在远程机器上安装用C#编写的Windows服务(以标准方式)的最佳方式是什么?我需要提供它应该运行的用户名和密码?使用给定的用户名在远程机器上安装windows服务
我将从MSBuild作为集成测试的一部分运行它。
编辑:我没有msi,我不想创建一个。
答
您可以使用SC命令。
sc.exe \\remotecomputer create newservice binpath= C:\Windows\System32\Newserv.exe start= auto obj= DOMAIN\username password= pwd
(注意空格等于后标志是重要的)
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>
答
从Powershell调用的WMI中调用的Installutil是一种可行的方法。
答
这可能是值得您检查一下我写的一个实用程序,它允许您在本地或远程计算机上安装/卸载/启动/停止Windows服务。如果你有需要添加的功能,让我知道(评论/ github问题或PM,我会很乐意)。
由于@Raj更多建议,它使用WMI从.NET调用。
看起来很有前途,但是我必须付钱吗? – Grzenio 2009-07-21 13:28:19
它包含在Windows中,可能在资源工具包中,启动命令提示符并键入sc以查看它是否已安装。 – 2009-07-21 13:47:36