简体   繁体   中英

System.ComponentModel.Win32Exception c#

This is my code:

    string damnfile = System.IO.Path.GetDirectoryName(choofdlog.FileName);
    ProcessStartInfo startInfo = new ProcessStartInfo("% ProgramFiles %\\Windows Defender\\MpCmdRun.exe");
    startInfo.WindowStyle = ProcessWindowStyle.Maximized;
    startInfo.Arguments = "-Scan -ScanType 3 -File" + damnfile;
    Process p = new Process();
    p.StartInfo = startInfo;
    p.Start();

As you can see, I want to run WinDefender scan for a specific file, but it throws error that the process is not found, but this code works:

        ProcessStartInfo startInfo = new ProcessStartInfo("netstat");
        startInfo.WindowStyle = ProcessWindowStyle.Maximized;
        startInfo.Arguments = "-a";
        Process p = new Process();
        p.StartInfo = startInfo;
        p.Start();

Also I want in the second code to redirect the cmd output to listBox, but thats the second problem, first help me with the defender scan please.

Solveded like now its opening, because I replaced

 ProcessStartInfo startInfo = new ProcessStartInfo("% ProgramFiles %\\Windows Defender\\MpCmdRun.exe");

with

ProcessStartInfo startInfo = new ProcessStartInfo(@"C:\Program Files\\Windows Defender\\MpCmdRun.exe");

Now appeared another problem: even I passed some arguments, the windows immediately close.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM