简体   繁体   English

使用给定的用户名在远程计算机上安装Windows服务

[英]Installing a windows service on remote machine using given username

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? 在远程计算机上安装用C#编写的Windows服务(以标准方式)的最佳方法是什么?我需要提供应该运行的用户名和密码?

I am going to run it from MSBuild as part of integration tests. 我将从MSBuild运行它作为集成测试的一部分。

EDIT: I don't have an msi and I don't want to create one. 编辑:我没有msi,我不想创建一个。

You can use the SC command. 您可以使用SC命令。

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> 

从Powershell调用的WMI调用的Installutil是一种方法。

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. 您可能值得查看我编写的实用程序,该实用程序允许您在本地或远程计算机上安装/卸载/启动/停止Windows服务。 If you have a feature you need added let me know (comment/github issues or PM and I'll happily oblige). 如果你有一个功能,你需要添加让我知道(评论/ github问题或PM,我很乐意)。

ServiceConfigurator on GitHub GitHub上的ServiceConfigurator

As @Raj More suggested, it uses WMI invoked from .NET. 正如@Raj More所建议的,它使用从.NET调用的WMI。

We used to use PsExec to do everything on remote machine. 我们曾经使用PsExec来做远程机器上的所有事情。 At this time I saw naother solution called PowerShell Remoting , but haven't tried myself. 这时我看到了另一个名为PowerShell Remoting的解决方案,但还没试过自己。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM