在遠程機器上安裝用C#編寫的Windows服務(以標準方式)的最佳方式是什麼?我需要提供它應該運行的用戶名和密碼?使用給定的用戶名在遠程機器上安裝windows服務
我將從MSBuild作爲集成測試的一部分運行它。
編輯:我沒有msi,我不想創建一個。
在遠程機器上安裝用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是一種可行的方法。
我們習慣用PsExec做遠程機器上的一切。 在這個時候我看到了叫做PowerShell Remoting的naother解決方案,但還沒有嘗試過自己。
這可能是值得您檢查一下我寫的一個實用程序,它允許您在本地或遠程計算機上安裝/卸載/啓動/停止Windows服務。如果你有需要添加的功能,讓我知道(評論/ github問題或PM,我會很樂意)。
由於@Raj更多建議,它使用WMI從.NET調用。
看起來很有前途,但是我必須付錢嗎? – Grzenio 2009-07-21 13:28:19
它包含在Windows中,可能在資源工具包中,啓動命令提示符並鍵入sc以查看它是否已安裝。 – 2009-07-21 13:47:36