簡體   English   中英

使用給定的用戶名在遠程計算機上安裝Windows服務

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

在遠程計算機上安裝用C#編寫的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,我很樂意)。

GitHub上的ServiceConfigurator

正如@Raj More所建議的,它使用從.NET調用的WMI。

我們曾經使用PsExec來做遠程機器上的所有事情。 這時我看到了另一個名為PowerShell Remoting的解決方案,但還沒試過自己。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM