WCF服务正在尝试在另一台计算机上运行针对远程的Powershell脚本



我正试图在我的计算机上托管的WCF服务上运行以下scrip。

string exePath = "C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe";
var ps1 = new ProcessStartInfo();
ps1.FileName = exePath;
ps1.Arguments = "-ExecutionPolicy Bypass -File C:\Users\fn070084\Desktop\Test2.ps1";
ps1.WorkingDirectory = Path.GetDirectoryName(exePath);
Process.Start(ps1);

如果我只运行这段代码,它就会在Visual studio上正确运行,但当我把它放在WCF服务器上的服务上时,它并没有做什么。

Test2文件的代码是这个

$LogFile = "\ComputerNameC$powershellLog" + $LongTime + ".txt" "Hello, I'm running Powershell through C#" >>$logFile

注:我把它写成";ComputerName";但在我的实际代码中,我使用了正确的计算机名称。

首先,确保安装WCF服务的服务器能够访问和调用该服务,正如您在本文档中看到的那样。

此外,您自己的计算机应该能够与服务器通信,调用方法可以访问。请参阅本帖。

最新更新