Domanda

I'm trying to run a CHKDSK in a cmd prompt launched with admin rights but the log file I create give me this message :

Access denied you do not have sufficient privileges. You have to invoke this utility running in elevated mode.

Here's my code :

            System.Diagnostics.Process process = new System.Diagnostics.Process();

            process.StartInfo.CreateNoWindow = true;
            process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            process.StartInfo.Verb = "runas";
            process.StartInfo.FileName = "cmd";
            process.StartInfo.Arguments = "/env /user:" + "Administrator" + " cmd";
            process.StartInfo.CreateNoWindow = true;
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardInput = true;
            process.Start();

            System.IO.StreamReader SR;
            System.IO.StreamWriter SW;

            Thread.Sleep(200);

            SR = process.StandardOutput;
            SW = process.StandardInput;

            string command = "CHKDSK.exe" + "/C" + " > " + "\"" + "C:\\Users\\Maha\\Documents\\log.txt" + "\"";

            SW.WriteLine(command);

            _errorMsg = process.StandardOutput.ReadToEnd();
            process.WaitForExit();

I tried to run CHKDSK in admins right aswell but nothing changed.

Thanks for the help.

Regards

È stato utile?

Soluzione

Try this:

Open your Application "Manifest File". Change the element requestedExecutionLevel to:

<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

I had a similar problem once ;-)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top