using System.Management;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
需添加引用 System.Management.Automation.dll
该文档到以下目录查找
C:\Windows\assembly\GAC_MSIL\System.Management.Automation\1.0.0.0__31bf3856ad364e35
执行PowerShell的方法:
public static void RunPs(String cmd) { using (Runspace runspace = RunspaceFactory.CreateRunspace()) { runspace.Open(); PowerShell ps = PowerShell.Create(); ps.Runspace = runspace; ps.AddScript(cmd); ps.Invoke(); } }
评论前必须登录!
注册