次のように、Power-shell から Windows サービスをインストールしようとしています。
$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 では正しいですが、VS 2012 では失敗します。InstallUtil が変更されているためです。
使用する必要があります
$sn = """" + $serviceName + " " + $exeName + """"
その理由は、InstallUtil(2.0) が自動的に引用符を追加するため、それらを無視する必要があるためです (回答のように)。ただし、InstallUtil(4) では、文字列の任意の場所に引用符が含まれている場合、これはスキップされます (これはバグですか? - 文字列の最初と最後に引用符があるかどうかを確認する必要がありました - 現在、これはすべての 2.0 コードを壊します)。
リフレクターはあなたの友達です。