【发布时间】:2011-04-19 11:11:09
【问题描述】:
我正在使用带有远程运行空间的 powershell 在远程机器上启动安装程序:
隐藏了一些代码,但你明白了...
我在 C# 中创建我的 PSCredential:
PSCredential pwd = new PSCredential(cred.UserName,PowerShellEngine.GenerateSecurePassword(cred.Password)); ConnectionInfo = 新的 WSManConnectionInfo( false, cred.HostName, 5985, "/wsman","http://schemas.microsoft.com/powershell/Microsoft.PowerShell",pwd); ConnectionInfo.AuthenticationMechanism = AuthenticationMechanism.Default;
创建运行空间,并执行脚本
//Load the script
string script = System.IO.File.ReadAllText(scriptFileName);
using (Runspace runspace = CreateRunSpace())
{
runspace.Open();
Pipeline pipeline = runspace.CreatePipeline();
pipeline.Commands.AddScript(script);
if (parameters != null)
{
foreach (KeyValuePair<string, string> parm in parameters)
{
pipeline.Commands[0].Parameters.Add(parm.Key, parm.Value);
}
}
pipeline.Commands.Add("out-default");
pipeline.Invoke();
}
脚本....(重要的部分)
$installStatement = [System.Diagnostics.Process]::Start($App, $Switches) $installStatement.WaitForExit() "进程退出代码:$LastExitCode"
这个过程开始很好..结束了:
MSI (s) (3C:18) [21:06:18:923]:产品:xxxx -- 错误 1920。服务 xxxx 无法启动。验证您是否有足够的权限来启动系统服务。
我已验证该进程以本地管理员身份运行,在命令提示符下运行良好,使用的是 PSExec。我认为这一定与运行空间本身的 WSMAN 权限或安全性有关?
是否需要设置策略或其他内容以允许 powershell 运行空间能够在安装程序中启动服务?
谢谢,加文
【问题讨论】: