I am trying to execute some series of statements in diskpart utility through C#. But i keep getting exception at p.start() that "The requested operation requires elevation" . I have tried application manifest file to run this as administrator but no use:
Process p = new Process(); // new instance of Process class
p.StartInfo.UseShellExecute = false; // do not start a new shell
p.StartInfo.RedirectStandardOutput = true; // Redirects the on screen results
p.StartInfo.FileName = "diskpart"; // executable to run
p.StartInfo.RedirectStandardInput = true; // Redirects the input commands
p.Start(); // Starts the process
p.StandardInput.WriteLine("select disk 1"); // Issues commands to diskpart
p.StandardInput.WriteLine("clean"); // |
p.StandardInput.WriteLine("create partition primary"); // |
p.StandardInput.WriteLine("select partition 1"); // |
p.StandardInput.WriteLine("format fs=ntfs quick"); // |
p.StandardInput.WriteLine("active"); // |
p.StandardInput.WriteLine("assign"); // |
p.StandardInput.WriteLine("exit"); // _\|/_
string output = p.StandardOutput.ReadToEnd(); // Places the output to a variable
p.WaitForExit(); // Waits for the exe to finish
MessageBox.Show(output);