我正试图从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的答案是正确的。但相对于2012年,它将失败。因为InstallUtil被修改了.
你应该使用$sn = """" + $serviceName + " " + $exeName + """"
原因是,InstallUtil(2.0)自动添加引号,因此我们应该忽略它们(如答案中所示)。但是InstallUtil(4),如果字符串在任何位置包含引号(这是一个错误吗?-他们应该检查字符串的开头和结尾是否有引号--目前这会破坏所有的2.0代码),就会跳过这个选项。
反射器是你的朋友。
发布于 2011-12-06 08:15:05
你的问题就在这一行:
$sn = """" + $serviceName + " " + $exeName + """"如果您要用更简单的方法替换它,或者这样做:
$sn = $serviceName.ToString() + " " + $exeName看起来不错
https://stackoverflow.com/questions/8396860
复制相似问题