[英]Executing Powershell Script fails in c#
在另一个StackOverflow帖子中找到了此代码。 您可以使用它来通过命令提示符执行Powershell脚本。 使用下面的函数并调用它对我有用:
ExecuteCommand("powershell -command \" & C:\\PowershellFileName.ps1\"");
public void ExecuteCommand(string Command)
{
ProcessStartInfo ProcessInfo;
Process Process;
ProcessInfo = new ProcessStartInfo("cmd.exe", "/K " + Command);
ProcessInfo.CreateNoWindow = true;
ProcessInfo.UseShellExecute = true;
Process = Process.Start(ProcessInfo);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.