2011-12-06 113 views
1

我試圖按如下方式從Power-shell安裝Windows服務。將參數傳遞給Powershell中的InstallUtil

$sn = """" + $serviceName + " " + $exeName + """" 
C:\Windows\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe -i /ServiceName=[$sn] $exeFilePath 

我收到以下異常。

Microsoft (R) .NET Framework Installation utility Version 2.0.50727.3053 
Copyright (c) Microsoft Corporation. All rights reserved. 

Exception occurred while initializing the installation: 
System.IO.FileNotFoundException: Could not load file or assembly 'file:///E:\Scheduled' or one of its dependencies. The system cannot f 
ind the file specified.. 

但下面的命令工作。

C:\Windows\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe -i /ServiceName=["Scheduled Download Service"] $exeFilePath 

我想安裝帶有動態名稱的Windows服務,並使用Power-shell傳遞服務名稱。任何幫助表示讚賞。

答案是VS 2008正確的,但由於InstallUtil被修改,在2012年VS將會失敗。

您應該使用 $sn = """" + $serviceName + " " + $exeName + """"

的原因是,InstallUtil(2.0)會自動添加引號,所以我們應該忽略它們(如答案)。但InstallUtil(4),如果字符串在任何位置包含引號(這是一個錯誤? - 它們應該檢查在字符串的開頭和結尾是否有引號 - 目前這會打破所有2.0代碼),這會被跳過。

Reflecter是你的朋友。

回答

3

您的問題是在這條線:

$sn = """" + $serviceName + " " + $exeName + """" 

如果你將簡單的東西取代它,或者像這樣做:

$sn = $serviceName.ToString() + " " + $exeName 

它將工作

+0

謝謝。它的工作..然而,服務名稱安裝爲[預定下載服務]。我期望預定的下載服務。 – Vivasaayi

+0

仍是[預定下載服務]。 – Vivasaayi

+0

預定下載服務 – Vivasaayi

相關問題