无法执行powershell cmd文件

时间:2017-06-04 10:42:34

标签: c# powershell

我想执行powershell cmd文件,但收到此错误消息:

System.Management.Automation.ItemNotFoundException: 'Cannot find path 
'C:\Users\HP\documents\visual studio 2017\Projects\XVPNC\XVPNC\scripts\HotelMode.cmd' 
because it does not exist.'

但我完全相信它存在! 我现在能做什么?或者哪里可能是个错误,拜托?

这是我的代码: (注意:即使我改变路径不包含空格,它的行为也相同!)

String scriptfilepath2 = "C:\\Users\\HP\\Documents\\Visual Studio 2017\\Projects\\XVPNC\\XVPNC\\scripts\\HotelMode.cmd";
            Runspace space = RunspaceFactory.CreateRunspace();
            space.Open();
            space.SessionStateProxy.Path.SetLocation(scriptfilepath2);
            Pipeline pipeline = space.CreatePipeline();
            var cresult = pipeline.Invoke();
            space.Close();

enter image description here enter image description here

0 个答案:

没有答案