public void CreateVHD() { //if (!ShouldContinue) return; //else ShouldContinue = false; StringBuilder sb = new StringBuilder(); if (WTGModel.choosedImageType == "vhd") { //sb.AppendLine("create vdisk file=" + this.VhdPath + " type=" + this.VhdType + " maximum=" + this.VhdSize); sb.AppendLine("select vdisk file=\"" + VhdPath + "\""); sb.AppendLine("attach vdisk"); sb.AppendLine("assign letter=v"); sb.AppendLine("exit"); } else { sb.AppendLine("create vdisk file=\"" + this.VhdPath + "\" type=" + this.VhdType + " maximum=" + this.VhdSize); sb.AppendLine("select vdisk file=\"" + this.VhdPath + "\""); sb.AppendLine("attach vdisk"); if (WTGModel.vhdPartitionType == "GPT") { sb.AppendLine("convert gpt"); } sb.AppendLine("create partition primary"); sb.AppendLine("format fs=ntfs quick"); sb.AppendLine("assign letter=v"); sb.AppendLine("exit"); } DiskpartScriptManager dsm = new DiskpartScriptManager(); Log.WriteLog("CreateVHDScript.log", sb.ToString()); //MessageBox.Show(sb.ToString()); dsm.Args = sb.ToString(); dsm.RunDiskpartScript(); //try //{ if (!Directory.Exists("V:\\")) { throw new VHDException(MsgManager.GetResString("Msg_VHDCreationError")); } if (WTGModel.choosedImageType != "vhd" && WTGModel.choosedImageType != "vhdx") { ApplyToVdisk(); } if (WTGModel.choosedImageType != "vhd" && WTGModel.choosedImageType != "vhdx" && !WTGModel.isWimBoot && !File.Exists(@"v:\windows\regedit.exe")) { throw new VHDException(MsgManager.GetResString("Msg_ApplyError")); //ErrorMsg er = new ErrorMsg(MsgManager.GetResString("Msg_ApplyError", MsgManager.ci)); //er.ShowDialog(); //this.ShouldContinue = false; } //else //{ // this.ShouldContinue = true; //} }
public static void SetNoDefaultDriveLetter(string uDisk) { StringBuilder sb = new StringBuilder(); sb.AppendLine("select volume " + uDisk.Substring(0, 1)); sb.AppendLine("attributes volume set nodefaultdriveletter"); DiskpartScriptManager dsm = new DiskpartScriptManager(); dsm.Args = sb.ToString(); dsm.RunDiskpartScript(); //attributes volume set nodefaultdriveletter }
public static void DiskPartReformatUD() { StringBuilder sb = new StringBuilder(); sb.AppendLine("select volume " + WTGOperation.ud.Substring(0, 1)); sb.AppendLine("clean"); sb.AppendLine("convert mbr"); sb.AppendLine("create partition primary"); sb.AppendLine("select partition 1"); sb.AppendLine("format fs=ntfs quick"); sb.AppendLine("active"); sb.AppendLine("assign letter=" + WTGOperation.ud.Substring(0, 1)); sb.AppendLine("exit"); DiskpartScriptManager dsm = new DiskpartScriptManager(); dsm.Args = sb.ToString(); dsm.RunDiskpartScript(); #region OldCode //ud = comboBox1.SelectedItem.ToString().Substring(0, 2) + "\\";//优盘 //if (DialogResult.No == MessageBox.Show("此操作将会清除移动磁盘所有分区的所有数据,确认?", "警告!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)) { return; } //if (DialogResult.No == MessageBox.Show("您确定要继续吗?", "警告!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)) { return; } //FileStream fs0 = new FileStream(WTGOperation.diskpartscriptpath + "\\dp.txt", FileMode.Create, FileAccess.Write); //fs0.SetLength(0); //StreamWriter sw0 = new StreamWriter(fs0, Encoding.Default); //string ws0 = ""; //try //{ // ws0 = "select volume " + WTGOperation.ud.Substring(0, 1); // sw0.WriteLine(ws0); // ws0 = "clean"; // sw0.WriteLine(ws0); // ws0 = "convert mbr"; // sw0.WriteLine(ws0); // ws0 = "create partition primary"; // sw0.WriteLine(ws0); // ws0 = "select partition 1"; // sw0.WriteLine(ws0); // ws0 = "format fs=ntfs quick"; // sw0.WriteLine(ws0); // ws0 = "active"; // sw0.WriteLine(ws0); // ws0 = "assign letter=" + WTGOperation.ud.Substring(0, 1); // sw0.WriteLine(ws0); // ws0 = "exit"; // sw0.WriteLine(ws0); //} //catch { } //sw0.Close(); //ProcessManager.ECMD("diskpart.exe", " /s \"" + WTGOperation.diskpartscriptpath + "\\dp.txt\""); //System.Diagnostics.Process dpc = System.Diagnostics.Process.Start("diskpart.exe", " /s " + Application.StartupPath + "\\dp.txt"); //dpc.WaitForExit(); #endregion }
public static void DetachVHD(string vhdPath) { StringBuilder sb = new StringBuilder(); sb.AppendLine("select vdisk file=\"" + vhdPath + "\""); sb.AppendLine("detach vdisk"); DiskpartScriptManager dsm = new DiskpartScriptManager(); dsm.Args = sb.ToString(); dsm.RunDiskpartScript(); }
public void AttachVHD(string vhdPath) { StringBuilder sb = new StringBuilder(); sb.AppendLine("select vdisk file=\"" + vhdPath + "\""); sb.AppendLine("attach vdisk"); sb.AppendLine("sel partition 1"); sb.AppendLine("assign letter=v"); sb.AppendLine("exit"); DiskpartScriptManager dsm = new DiskpartScriptManager(); dsm.Args = sb.ToString(); dsm.RunDiskpartScript(); //GenerateAttachVHDScript(this.vhdPath); //ProcessManager.ECMD("diskpart.exe", " /s \"" + WTGModel.diskpartScriptPath + "\\attach.txt\""); }
public static void DetachVHDExtra() { DiskpartScriptManager dsm = new DiskpartScriptManager(true); dsm.Args = "list vdisk"; dsm.RunDiskpartScript(); //MessageBox.Show(dsm.outputFilePath); string dpoutput = File.ReadAllText(dsm.OutputFilePath, Encoding.Default); //MessageBox.Show(dpoutput); MatchCollection mc = Regex.Matches(dpoutput, @"([a-z]:\\.*win8\.vhd[x]?)", RegexOptions.IgnoreCase); foreach (Match item in mc) { //MessageBox.Show(item.Groups[1].Value); DetachVHD(item.Groups[1].Value); } dsm.DeleteOutputFile(); }
private void TwiceAttachVHDAndWriteBootFile() { if (!NeedTwiceAttach) { return; } //if (!ShouldContinue) return; //AttachVHD(StringOperation.Combine(WTGOperation.WTGModel.ud, win8VhdFile)); StringBuilder sb = new StringBuilder(); sb.AppendLine("select vdisk file=" + StringUtility.Combine(WTGModel.ud, WTGModel.win8VHDFileName)); sb.AppendLine("attach vdisk"); sb.AppendLine("sel partition 1"); sb.AppendLine("assign letter=v"); sb.AppendLine("exit"); DiskpartScriptManager dsm = new DiskpartScriptManager(); dsm.Args = sb.ToString(); dsm.RunDiskpartScript(); if (!Directory.Exists("V:\\")) { Log.WriteLog("TwiceAttachVhdError.log", "二次加载VHD失败"); throw new VHDException(MsgManager.GetResString("Msg_VHDCreationError", MsgManager.ci)); } //需要二次加载,一定不是需要写入X盘的UEFI模式 if (WTGModel.ntfsUefiSupport) { BootFileOperation.BcdbootWriteBootFile(@"V:\", WTGModel.ud, FirmwareType.ALL); } else { BootFileOperation.BcdbootWriteBootFile(@"V:\", WTGModel.ud, FirmwareType.BIOS); } DetachVHD(StringUtility.Combine(WTGModel.ud, WTGModel.win8VHDFileName)); if (!File.Exists(WTGModel.ud + "\\Boot\\BCD")) { CopyVHDBootFiles(); //Log.WriteLog ("TwiceAttachFailed.log") } }
private void TwiceAttachVHDAndWriteBootFile() { if (!NeedTwiceAttach) return; //if (!ShouldContinue) return; //AttachVHD(StringOperation.Combine(WTGOperation.ud, win8VhdFile)); StringBuilder sb = new StringBuilder(); sb.AppendLine("select vdisk file=" + StringUtility.Combine(WTGOperation.ud, win8VHDFileName)); sb.AppendLine("attach vdisk"); sb.AppendLine("sel partition 1"); sb.AppendLine("assign letter=v"); sb.AppendLine("exit"); DiskpartScriptManager dsm = new DiskpartScriptManager(); Log.WriteLog("TwiceAttachVhd.log", sb.ToString()); dsm.Args = sb.ToString(); dsm.RunDiskpartScript(); try { if (!Directory.Exists("V:\\")) { Log.WriteLog("TwiceAttachVhdError.log", "二次加载VHD失败"); } } catch { throw new VHDException(MsgManager.GetResString("Msg_VHDCreationError", MsgManager.ci)); //创建VHD失败,未知错误 //ErrorMsg er = new ErrorMsg(MsgManager.GetResString("Msg_VHDCreationError", MsgManager.ci)); //er.ShowDialog(); //this.ShouldContinue = false; //shouldcontinue = false; } //需要二次加载,一定不是UEFI模式 BootFileOperation.BcdbootWriteBootFile(@"V:\", ud, bcdbootFileName, FirmwareType.ALL); DetachVHD(StringUtility.Combine(ud, win8VHDFileName)); if (!File.Exists(ud + "\\Boot\\BCD")) { CopyVHDBootFiles(); //Log.WriteLog ("TwiceAttachFailed.log") } }
public void CreateVHD() { //if (!ShouldContinue) return; //else ShouldContinue = false; StringBuilder sb = new StringBuilder(); if (choosedFileType == "vhd") { //sb.AppendLine("create vdisk file=" + this.VhdPath + " type=" + this.VhdType + " maximum=" + this.VhdSize); sb.AppendLine("select vdisk file=" + this.VhdPath); sb.AppendLine("attach vdisk"); sb.AppendLine("assign letter=v"); sb.AppendLine("exit"); } else { sb.AppendLine("create vdisk file=" + this.VhdPath + " type=" + this.VhdType + " maximum=" + this.VhdSize); sb.AppendLine("select vdisk file=" + this.VhdPath); sb.AppendLine("attach vdisk"); if (userSettings.VHDPartitionType == PartitionTableType.GPT) { sb.AppendLine("convert gpt"); } sb.AppendLine("create partition primary"); sb.AppendLine("format fs=ntfs quick"); sb.AppendLine("assign letter=v"); sb.AppendLine("exit"); } DiskpartScriptManager dsm = new DiskpartScriptManager(); Log.WriteLog("CreateVHDScript.log", sb.ToString()); //MessageBox.Show(sb.ToString()); dsm.Args = sb.ToString(); dsm.RunDiskpartScript(); //try //{ if (!Directory.Exists("V:\\")) { throw new VHDException(MsgManager.GetResString("Msg_VHDCreationError")); //ErrorMsg er = new ErrorMsg(MsgManager.GetResString("Msg_VHDCreationError", MsgManager.ci)); //er.ShowDialog(); //this.ShouldContinue = false; //shouldcontinue = false; //return; } //else //{ // //this.ShouldContinue = true; //} //} //catch //{ // throw new VHDException(MsgManager.GetResString("Msg_VHDCreationError")); // //创建VHD失败,未知错误 // //ErrorMsg er = new ErrorMsg(MsgManager.GetResString("Msg_VHDCreationError", MsgManager.ci)); // //er.ShowDialog(); // //this.ShouldContinue = false; // //shouldcontinue = false; //} if (choosedFileType != "vhd" && choosedFileType != "vhdx") { ApplyToVdisk(); } if (choosedFileType != "vhd" && choosedFileType != "vhdx" && !isWimBoot && !File.Exists(@"v:\windows\regedit.exe")) { throw new VHDException(MsgManager.GetResString("Msg_ApplyError")); //ErrorMsg er = new ErrorMsg(MsgManager.GetResString("Msg_ApplyError", MsgManager.ci)); //er.ShowDialog(); //this.ShouldContinue = false; } //else //{ // this.ShouldContinue = true; //} }
public void AttachVHD(string vhdPath) { StringBuilder sb = new StringBuilder(); sb.AppendLine("select vdisk file=" + vhdPath); sb.AppendLine("attach vdisk"); sb.AppendLine("sel partition 1"); sb.AppendLine("assign letter=v"); sb.AppendLine("exit"); DiskpartScriptManager dsm = new DiskpartScriptManager(); dsm.Args = sb.ToString(); dsm.RunDiskpartScript(); //GenerateAttachVHDScript(this.vhdPath); //ProcessManager.ECMD("diskpart.exe", " /s \"" + diskpartscriptpath + "\\attach.txt\""); }
public static void DetachVHD(string vhdPath) { StringBuilder sb = new StringBuilder(); sb.AppendLine("select vdisk file=" + vhdPath); sb.AppendLine("detach vdisk"); DiskpartScriptManager dsm = new DiskpartScriptManager(); dsm.Args = sb.ToString(); dsm.RunDiskpartScript(); }
private void GoWrite() { try { //wimpart = ChoosePart.part;//读取选择分卷,默认选择第一分卷 #region 各种提示 //各种提示 if (wimbox.Text.ToLower().Substring(wimbox.Text.Length - 3, 3) != "wim" && wimbox.Text.ToLower().Substring(wimbox.Text.Length - 3, 3) != "esd" && wimbox.Text.ToLower().Substring(wimbox.Text.Length - 3, 3) != "vhd" && wimbox.Text.ToLower().Substring(wimbox.Text.Length - 4, 4) != "vhdx")//不是WIM文件 { // MsgManager.getResString("Msg_chooseinstallwim") //镜像文件选择错误!请选择install.wim! MessageBox.Show(MsgManager.GetResString("Msg_chooseinstallwim", MsgManager.ci)); return; } else { //请选择install.wim文件 if (!System.IO.File.Exists(wimbox.Text)) { MessageBox.Show(MsgManager.GetResString("Msg_chooseinstallwim", MsgManager.ci), MsgManager.GetResString("Msg_error", MsgManager.ci), MessageBoxButtons.OK, MessageBoxIcon.Error); return; }//文件不存在. WTGOperation.imageFilePath = wimbox.Text; } if (!Directory.Exists(WTGOperation.ud)) { MessageBox.Show(MsgManager.GetResString("Msg_chooseud", MsgManager.ci) + "!", MsgManager.GetResString("Msg_error", MsgManager.ci), MessageBoxButtons.OK, MessageBoxIcon.Error); return; }//是否选择优盘 if (DiskOperation.GetHardDiskSpace(WTGOperation.ud) <= 12582912) //优盘容量<12 GB提示 { //MsgManager.getResString("Msg_DiskSpaceWarning") //可移动磁盘容量不足16G,继续写入可能会导致程序出错!您确定要继续吗? if (DialogResult.No == MessageBox.Show(MsgManager.GetResString("Msg_DiskSpaceWarning", MsgManager.ci), MsgManager.GetResString("Msg_warning", MsgManager.ci), MessageBoxButtons.YesNo, MessageBoxIcon.Warning)) { return; } } if (DiskOperation.GetHardDiskSpace(WTGOperation.ud) <= numericUpDown1.Value * 1048576) { //优盘容量小于VHD设定大小,请修改设置! //MsgManager.getResString("Msg_DiskSpaceError") MessageBox.Show(MsgManager.GetResString("Msg_DiskSpaceError", MsgManager.ci), MsgManager.GetResString("Msg_error", MsgManager.ci), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //MsgManager.getResString("Msg_ConfirmChoose") //请确认您所选择的 //MsgManager.getResString("Msg_Disk_Space") 盘,容量 //Msg_FormatTip //GB 是将要写入的优盘或移动硬盘\n误格式化,后果自负! if (DialogResult.No == MessageBox.Show(MsgManager.GetResString("Msg_ConfirmChoose", MsgManager.ci) + WTGOperation.ud.Substring(0, 1) + MsgManager.GetResString("Msg_Disk_Space", MsgManager.ci) + DiskOperation.GetHardDiskSpace(WTGOperation.ud) / 1024 / 1024 + MsgManager.GetResString("Msg_FormatTip", MsgManager.ci), MsgManager.GetResString("Msg_warning", MsgManager.ci), MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk)) { return; } if (checkBoxdiskpart.Checked && !checkBoxuefi.Checked && !checkBoxuefimbr.Checked)//勾选重新分区提示 { //MsgManager.getResString("Msg_Repartition") //Msg_Repartition //您勾选了重新分区,优盘或移动硬盘上的所有文件将被删除!\n注意是整个磁盘,不是一个分区! if (DialogResult.No == MessageBox.Show(MsgManager.GetResString("Msg_Repartition", MsgManager.ci), MsgManager.GetResString("Msg_warning", MsgManager.ci), MessageBoxButtons.YesNo, MessageBoxIcon.Warning)) { return; } //MsgManager.getResString("Msg_DoWhat") //如果您不清楚您在做什么,请立即停止操作! if (DialogResult.No == MessageBox.Show(MsgManager.GetResString("Msg_DoWhat", MsgManager.ci), MsgManager.GetResString("Msg_warning", MsgManager.ci), MessageBoxButtons.YesNo, MessageBoxIcon.Warning)) { return; } DiskOperation.DiskPartReformatUD(); //diskPart(); } else//普通格式化提示 { if (!checkBoxunformat.Checked) { //MsgManager.getResString("Msg_FormatWarning") //盘将会被格式化,此操作将不可恢复,您确定要继续吗?\n由于写入时间较长,请您耐心等待!\n写入过程中弹出写入可能无效属于正常现象,选是即可。 if (DialogResult.No == MessageBox.Show(WTGOperation.ud.Substring(0, 1) + MsgManager.GetResString("Msg_FormatWarning", MsgManager.ci), MsgManager.GetResString("Msg_warning", MsgManager.ci), MessageBoxButtons.YesNo, MessageBoxIcon.Warning)) { return; } //if (DialogResult.No == MessageBox.Show("如果您不清楚您在做什么,请立即停止操作!", "警告!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)) { return; } } } #endregion ///////删除旧LOG文件 Log.DeleteAllLogs(); //ProcessManager.SyncCMD ("cmd.exe /c del /f /s /q \""+Application .StartupPath +"\\logs\\*.*\""); //////////////将程序运行信息写入LOG WriteProgramRunInfoToLog(); if (checkBoxuefi.Checked) { //UEFI+GPT if (System.Environment.OSVersion.ToString().Contains("5.1") || System.Environment.OSVersion.ToString().Contains("5.2")) { //MsgManager.getResString("Msg_XPUefiError") //XP系统不支持UEFI模式写入 MessageBox.Show(MsgManager.GetResString("Msg_XPUefiError", MsgManager.ci)); return; } if (WTGOperation.udString.Contains("Removable Disk")) { //MsgManager.getResString("Msg_UefiError") //此优盘不支持UEFI模式\n只有 Fixed Disk格式支持\n详情请看论坛说明! MessageBox.Show(MsgManager.GetResString("Msg_UefiError", MsgManager.ci), MsgManager.GetResString("Msg_error", MsgManager.ci), MessageBoxButtons.OK, MessageBoxIcon.Error); VisitWeb("http://bbs.luobotou.org/thread-6506-1-1.html"); return; } //MsgManager.getResString("Msg_UefiFormatWarning") //您所选择的是UEFI模式,此模式将会格式化您的整个移动磁盘!\n注意是整个磁盘!!!\n程序将会删除所有优盘分区! if (DialogResult.No == MessageBox.Show(MsgManager.GetResString("Msg_UefiFormatWarning", MsgManager.ci), MsgManager.GetResString("Msg_warning", MsgManager.ci), MessageBoxButtons.YesNo, MessageBoxIcon.Warning)) { return; } DiskpartScriptManager dsm = new DiskpartScriptManager(); dsm.RunDiskpartScriptByScriptFile(DiskOperation.GenerateGPTAndUEFIScript(WTGOperation.userSettings.EFIPartitionSize.ToString(), WTGOperation.ud)); //ProcessManager.ECMD("diskpart.exe", " /s \"" + WTGOperation.diskpartScriptPath + "\\uefi.txt\""); if (radiochuantong.Checked) { //UEFI+GPT 传统 UefiGptTypical(); } else // UEFI+GPT VHD、VHDX模式 { UefiGptVhdVhdx(); } RemoveLetterX(); //Finish f = new Finish(); //f.ShowDialog(); FinishSuccessful(); //MessageBox.Show("UEFI模式写入完成!\n请重启电脑用优盘启动\n如有问题,可去论坛反馈!","完成啦!",MessageBoxButtons .OK ,MessageBoxIcon.Information ); } else if (checkBoxuefimbr.Checked) { //UEFI+MBR if (WTGOperation.udString.Contains("Removable Disk")) { MessageBox.Show(MsgManager.GetResString("Msg_UefiError", MsgManager.ci), MsgManager.GetResString("Msg_error", MsgManager.ci), MessageBoxButtons.OK, MessageBoxIcon.Error); VisitWeb("http://bbs.luobotou.org/thread-6506-1-1.html"); return; } if (DialogResult.No == MessageBox.Show(MsgManager.GetResString("Msg_UefiFormatWarning", MsgManager.ci), MsgManager.GetResString("Msg_warning", MsgManager.ci), MessageBoxButtons.YesNo, MessageBoxIcon.Warning)) { return; } DiskpartScriptManager dsm = new DiskpartScriptManager(); dsm.RunDiskpartScriptByScriptFile(DiskOperation.GenerateMBRAndUEFIScript(WTGOperation.userSettings.EFIPartitionSize.ToString(), WTGOperation.ud)); //ProcessManager.ECMD("diskpart.exe", " /s \"" + WTGOperation.diskpartScriptPath + "\\uefimbr.txt\""); if (radiochuantong.Checked) { UEFIMBRTypical(); } else //uefi MBR VHD、VHDX模式 { UefiMbrVHDVHDX(); } //MessageBox.Show("UEFI模式写入完成!\n请重启电脑用优盘启动\n如有问题,可去论坛反馈!", "完成啦!", MessageBoxButtons.OK, MessageBoxIcon.Information); } else //非UEFI模式 { //传统 #region 格式化 if (WTGOperation.udString.Contains("Removable Disk") && radiochuantong.Checked) { if (DialogResult.No == MessageBox.Show(MsgManager.GetResString("Msg_Legacywarning", MsgManager.ci), MsgManager.GetResString("Msg_warning", MsgManager.ci), MessageBoxButtons.YesNo, MessageBoxIcon.Warning)) { return; } } if (!checkBoxdiskpart.Checked && !checkBoxunformat.Checked)//普通格式化 { ProcessManager.ECMD("cmd.exe", "/c format " + WTGOperation.ud.Substring(0, 2) + "/FS:ntfs /q /V: /Y"); // } //if (WTGOperation.forceFormat) //强制格式化 //{ // System.Diagnostics.Process ud1 = System.Diagnostics.Process.Start(Application.StartupPath + "\\files\\" + "\\fbinst.exe", (" " + WTGOperation.ud.Substring(0, 2) + " format -r -f"));//Format disk // ud1.WaitForExit(); //} #endregion ///////////////////////////////////正式开始//////////////////////////////////////////////// if (radiochuantong.Checked) { NonUEFITypical(); } else //非UEFI VHD VHDX { NonUEFIVHDVHDX(); } } } catch (UserCancelException ex) { MessageBox.Show(ex.Message); } }
private void RemoveLetterX() { try { DiskpartScriptManager dsm = new DiskpartScriptManager(); StringBuilder args = new StringBuilder(); args.AppendLine("select volume x"); args.AppendLine("remove"); args.AppendLine("exit"); dsm.Args = args.ToString(); dsm.RunDiskpartScript(); } catch (Exception ex) { //Console.WriteLine(ex.ToString()); Log.WriteLog("removeLetterX.log", ex.ToString()); } //ProcessManager.ECMD("diskpart.exe", " /s \"" + WTGOperation.diskpartScriptPath + "\\removex.txt\""); }
private void GoWrite() { try { //wimpart = ChoosePart.part;//读取选择分卷,默认选择第一分卷 #region 各种提示 //各种提示 if (lblWim.Text.ToLower().Substring(lblWim.Text.Length - 3, 3) != "wim" && lblWim.Text.ToLower().Substring(lblWim.Text.Length - 3, 3) != "esd" && lblWim.Text.ToLower().Substring(lblWim.Text.Length - 3, 3) != "vhd" && lblWim.Text.ToLower().Substring(lblWim.Text.Length - 4, 4) != "vhdx")//不是WIM文件 { //镜像文件选择错误!请选择install.wim! MessageBox.Show(MsgManager.GetResString("Msg_chooseinstallwim", MsgManager.ci), MsgManager.GetResString("Msg_error", MsgManager.ci), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { //请选择install.wim文件 if (!System.IO.File.Exists(lblWim.Text)) { MessageBox.Show(MsgManager.GetResString("Msg_chooseinstallwim", MsgManager.ci), MsgManager.GetResString("Msg_error", MsgManager.ci), MessageBoxButtons.OK, MessageBoxIcon.Error); return; }//文件不存在. WTGModel.imageFilePath = lblWim.Text; } if (!Directory.Exists(WTGModel.ud)) { MessageBox.Show(MsgManager.GetResString("Msg_chooseud", MsgManager.ci) + "!", MsgManager.GetResString("Msg_error", MsgManager.ci), MessageBoxButtons.OK, MessageBoxIcon.Error); return; }//是否选择优盘 if (DiskOperation.GetHardDiskSpace(WTGModel.ud) <= 12582912) //优盘容量<12 GB提示 { //MsgManager.getResString("Msg_DiskSpaceWarning") //可移动磁盘容量不足16G,继续写入可能会导致程序出错!您确定要继续吗? if (DialogResult.No == MessageBox.Show(MsgManager.GetResString("Msg_DiskSpaceWarning", MsgManager.ci), MsgManager.GetResString("Msg_warning", MsgManager.ci), MessageBoxButtons.YesNo, MessageBoxIcon.Warning)) { return; } } if (DiskOperation.GetHardDiskSpace(WTGModel.ud) <= numericUpDown1.Value * 1048576) { //优盘容量小于VHD设定大小,请修改设置! //MsgManager.getResString("Msg_DiskSpaceError") MessageBox.Show(MsgManager.GetResString("Msg_DiskSpaceError", MsgManager.ci), MsgManager.GetResString("Msg_error", MsgManager.ci), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //MsgManager.getResString("Msg_ConfirmChoose") //请确认您所选择的 //MsgManager.getResString("Msg_Disk_Space") 盘,容量 //Msg_FormatTip //GB 是将要写入的优盘或移动硬盘\n误格式化,后果自负! StringBuilder formatTip = new StringBuilder(); formatTip.AppendLine(MsgManager.GetResString("Msg_ConfirmChoose", MsgManager.ci)); formatTip.AppendFormat(WTGModel.udString); formatTip.AppendLine(MsgManager.GetResString("Msg_FormatTip", MsgManager.ci)); if (checkBoxDiskpart.Checked && !checkBoxUefigpt.Checked && !checkBoxUefimbr.Checked)//勾选重新分区提示 { formatTip.AppendLine(MsgManager.GetResString("Msg_Repartition", MsgManager.ci)); FormatAlert fa = new FormatAlert(formatTip.ToString()); //MsgManager.getResString("Msg_Repartition") //您勾选了重新分区,优盘或移动硬盘上的所有文件将被删除!\n注意是整个磁盘,不是一个分区! if (DialogResult.Yes != fa.ShowDialog()) { return; } DiskOperation.DiskPartReformatUD(); } else//普通格式化提示 { if (!WTGModel.userSettings.DoNotFormat) { formatTip.AppendLine(MsgManager.GetResString("Msg_FormatWarning", MsgManager.ci)); FormatAlert fa = new FormatAlert(formatTip.ToString()); if (DialogResult.Yes != fa.ShowDialog()) { return; } } else { FormatAlert fa = new FormatAlert(formatTip.ToString()); if (DialogResult.Yes != fa.ShowDialog()) { return; } } } #endregion SystemSleepManagement.PreventSleep(); //删除旧LOG文件 Log.DeleteAllLogs(); ProcessManager.KillProcessByName("bootice.exe"); WriteProgramRunInfoToLog(); writeSw.Restart(); if (checkBoxUefigpt.Checked) { //UEFI+GPT if (System.Environment.OSVersion.ToString().Contains("5.1") || System.Environment.OSVersion.ToString().Contains("5.2")) { //MsgManager.getResString("Msg_XPUefiError") //XP系统不支持UEFI模式写入 MessageBox.Show(MsgManager.GetResString("Msg_XPUefiError", MsgManager.ci)); return; } if (WTGModel.udString.Contains("Removable Disk")) { //普通优盘UEFI WTGModel.isLegacyUdiskUefi = true; RemoveableDiskUefiGpt(); FinishSuccessful(); } else { //MsgManager.getResString("Msg_UefiFormatWarning") //您所选择的是UEFI模式,此模式将会格式化您的整个移动磁盘!\n注意是整个磁盘!!!\n程序将会删除所有优盘分区! if (DialogResult.No == MessageBox.Show(MsgManager.GetResString("Msg_UefiFormatWarning", MsgManager.ci), MsgManager.GetResString("Msg_warning", MsgManager.ci), MessageBoxButtons.YesNo, MessageBoxIcon.Warning)) { return; } DiskpartScriptManager dsm = new DiskpartScriptManager(); dsm.RunDiskpartScriptByScriptFile(DiskOperation.GenerateGPTAndUEFIScript(WTGModel.userSettings.EFIPartitionSize.ToString(), WTGModel.ud)); //ProcessManager.ECMD("diskpart.exe", " /s \"" + WTGOperation.diskpartScriptPath + "\\uefi.txt\""); if (radiobtnLegacy.Checked) { //UEFI+GPT 传统 UefiGptTypical(); } else // UEFI+GPT VHD、VHDX模式 { UefiGptVhdVhdx(); } } } else if (checkBoxUefimbr.Checked) { //UEFI+MBR if (WTGModel.udString.Contains("Removable Disk")) { MessageBox.Show(MsgManager.GetResString("Msg_UefiError", MsgManager.ci), MsgManager.GetResString("Msg_error", MsgManager.ci), MessageBoxButtons.OK, MessageBoxIcon.Error); VisitWeb("http://bbs.luobotou.org/thread-6506-1-1.html"); return; } if (DialogResult.No == MessageBox.Show(MsgManager.GetResString("Msg_UefiFormatWarning", MsgManager.ci), MsgManager.GetResString("Msg_warning", MsgManager.ci), MessageBoxButtons.YesNo, MessageBoxIcon.Warning)) { return; } DiskpartScriptManager dsm = new DiskpartScriptManager(); dsm.RunDiskpartScriptByScriptFile(DiskOperation.GenerateMBRAndUEFIScript(WTGModel.userSettings.EFIPartitionSize.ToString(), WTGModel.ud)); //ProcessManager.ECMD("diskpart.exe", " /s \"" + WTGOperation.diskpartScriptPath + "\\uefimbr.txt\""); if (radiobtnLegacy.Checked) { UEFIMBRTypical(); } else //uefi MBR VHD、VHDX模式 { UefiMbrVHDVHDX(); } //MessageBox.Show("UEFI模式写入完成!\n请重启电脑用优盘启动\n如有问题,可去论坛反馈!", "完成啦!", MessageBoxButtons.OK, MessageBoxIcon.Information); } else //非UEFI模式 { //传统 #region 格式化 if (WTGModel.udString.Contains("Removable Disk") && radiobtnLegacy.Checked) { if (DialogResult.No == MessageBox.Show(MsgManager.GetResString("Msg_Legacywarning", MsgManager.ci), MsgManager.GetResString("Msg_warning", MsgManager.ci), MessageBoxButtons.YesNo, MessageBoxIcon.Warning)) { return; } } if (!checkBoxDiskpart.Checked && !WTGModel.userSettings.DoNotFormat)//普通格式化 { ProcessManager.ECMD("cmd.exe", "/c format " + WTGModel.ud.Substring(0, 2) + "/FS:ntfs /q /V: /Y"); // } //if (WTGOperation.forceFormat) //强制格式化 //{ // System.Diagnostics.Process ud1 = System.Diagnostics.Process.Start(Application.StartupPath + "\\files\\" + "\\fbinst.exe", (" " + WTGOperation.ud.Substring(0, 2) + " format -r -f"));//Format disk // ud1.WaitForExit(); //} #endregion ///////////////////////////////////正式开始//////////////////////////////////////////////// if (radiobtnLegacy.Checked) { NonUEFITypical(); } else //非UEFI VHD VHDX { NonUEFIVHDVHDX(false); } } } catch (UserCancelException ex) { ErrorMsg em = new ErrorMsg(ex.Message); em.ShowDialog(); } catch (Exception ex) { ErrorMsg em = new ErrorMsg(ex.Message); em.ShowDialog(); } finally { writeSw.Stop(); SystemSleepManagement.ResotreSleep(); } }