编写一个DiskPart.bat ,里面内容是diskpart / s 1.txt
1.txt里面内容如下:
select disk 0
select partition 3
set id = 0c
exit
c#代码如下:
Process proc = new Process();
proc.StartInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
proc.StartInfo.FileName = "DiskPart.bat";
proc.StartInfo.Verb = "runas";
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.UseShellExecute = false;
//proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.Start();
proc.WaitForExit();
string output = proc.StandardOutput.ReadToEnd();
执行的时候会闪一个DOS窗口,怎么能不闪现DOS窗口?