我尝试从 WPF 应用程序(在App.xaml.cs中)调用 powershell 脚本,如下所示:private void Application_Startup(object sender, StartupEventArgs e){ var process = new Process(); process.StartInfo.FileName = "powershell.exe"; process.StartInfo.Arguments = @"\\WIN-SRV-2019\Betreuung-Release\Install.ps1"; process.Start(); process.WaitForExit(); // ...}结果,powershell 窗口很快打开,然后在不执行脚本的情况下立即关闭。当我在命令行 (CMD) 上执行以下命令时:C:\Users\Entwicklung>powershell \\WIN-SRV-2019\Betreuung-Release\Install.ps1...一切正常。脚本按预期执行。我究竟做错了什么?
1 回答
元芳怎么了
TA贡献1798条经验 获得超7个赞
我终于发现了问题所在。我不得不添加-executionpolicy unrestricted到参数中:
private void Application_Startup(object sender, StartupEventArgs e)
{
var process = new Process();
process.StartInfo.FileName = "powershell.exe";
process.StartInfo.Arguments = @"-executionpolicy unrestricted \\WIN-SRV-2019\Betreuung-Release\Install.ps1";
process.Start();
process.WaitForExit();
// ...
}
- 1 回答
- 0 关注
- 137 浏览
添加回答
举报
0/150
提交
取消