我试图通过C#在diskpart实用程序中执行一系列语句。但是我一直在p.start()处获得异常#34;请求的操作需要提升" 。我已尝试过应用程序清单文件以管理员身份运行它,但没有用:
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);