我正在尝试使用以下运行空间设置首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.
有谁知道代码中有什么问题?