术语“Set-MpPreference”'在通过C#

时间:2017-12-15 00:52:47

标签: c# powershell runspace windows-defender

我正在尝试使用以下运行空间将首选项DisableRealtimeMonitoring设置为false

try
{
    Runspace runspace = RunspaceFactory.CreateRunspace();
    runspace.Open();
    Pipeline pipeline = runspace.CreatePipeline();
    Command setMp = new Command("Set-MpPreference");
    string paramRT = "DisableRealtimeMonitoring";
    bool pF = Convert.ToBoolean(Convert.ToInt32("0"));
    setMp.Parameters.Add(paramRT, pF);
    pipeline.Commands.Add(setMp);
    runspace.Close();
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message);
}

此运行空间应相当于以下PS命令:

Set-MpPreference -DisableRealtimeMonitoring 0

PS命令​​就像魅力一样,而上面的运行空间代码即使禁用UAC也不起作用。出于故障排除的目的,我对代码进行了一些修改以捕获错误,如下所示:

  

The term 'Set-MpPreference' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

有人知道代码中有什么问题吗?

0 个答案:

没有答案