/// <summary> /// 执行Diskpart命令 /// </summary> //public void RunDiskpartScriptByScriptFile(string scriptFile) //{ // StringBuilder dpargs = new StringBuilder(); // dpargs.Append(" /s \""); // dpargs.Append(scriptFile); // try // { // ProcessManager.ECMD("diskpart.exe", dpargs.ToString()); // } // catch (Exception) // { // //ProcessManager.KillProcessByName("diskpart.exe"); // throw; // } //} public void RunDiskpartScript() { OutputFilePath = Path.GetTempFileName(); CreateScriptFile(); StringBuilder dpargs = new StringBuilder(); dpargs.Append(" /s \""); dpargs.Append(TempScriptFile); dpargs.Append("\""); if (this.OutputToFile) { dpargs.Append(" > "); dpargs.Append("\""); dpargs.Append(this.OutputFilePath); dpargs.Append("\""); ProcessManager.SyncCMD("diskpart.exe" + dpargs.ToString()); } else { try { ProcessManager.ECMD("diskpart.exe", dpargs.ToString()); } catch (Exception) { //ProcessManager.KillProcessByName("diskpart.exe"); throw; } } //System.Console.WriteLine(File.ReadAllText (this.scriptPath)); //System.Console.WriteLine(dpargs.ToString()); //System.Windows.Forms.MessageBox.Show(dpargs.ToString()); //System.Console.WriteLine(File.ReadAllText (this.outputFilePath)); FileOperation.DeleteFile(TempScriptFile); }
public static string AutoChooseESDImageIndex(string esdPath) { string outputFilePath = Path.GetTempFileName(); StringBuilder args = new StringBuilder(); args.Append(" /get-wiminfo /wimfile:\""); args.Append(esdPath); args.Append("\" /english"); args.Append(" > "); args.Append("\""); args.Append(outputFilePath); args.Append("\""); //ProcessManager.RunDism(args.ToString()); ProcessManager.SyncCMD("dism.exe" + args.ToString()); string outputFileText = File.ReadAllText(outputFilePath); MatchCollection mc = Regex.Matches(outputFileText, @"Index"); if (mc.Count > 1) { FileOperation.DeleteFile(outputFilePath); return("4"); } else { FileOperation.DeleteFile(outputFilePath); return("1"); } //Match match = Regex.Match(outputFileText, @"Index :([1-9]).+Windows Technical Preview", RegexOptions.Singleline); //MessageBox.Show(match.Groups[1].Value); //ProcessManager.ECMD("diskpart.exe", args.ToString()); //System.Console.WriteLine(File.ReadAllText (this.scriptPath)); //System.Console.WriteLine(dpargs.ToString()); //System.Windows.Forms.MessageBox.Show(dpargs.ToString()); //System.Console.WriteLine(File.ReadAllText (this.outputFilePath)); }
/// <summary> /// 删除输出文件 /// </summary> public void DeleteOutputFile() { FileOperation.DeleteFile(this.OutputFilePath); }