Ejemplo n.º 1
0
        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;
            //}
        }
Ejemplo n.º 2
0
 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
 }
Ejemplo n.º 3
0
        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
        }
Ejemplo n.º 4
0
        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();
        }
Ejemplo n.º 5
0
        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\"");
        }
Ejemplo n.º 6
0
        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();
        }
Ejemplo n.º 7
0
        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")
            }
        }
Ejemplo n.º 8
0
        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")
            }
        }
Ejemplo n.º 9
0
        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;
            //}
        }
Ejemplo n.º 10
0
        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\"");
        }
Ejemplo n.º 11
0
 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();
 }
Ejemplo n.º 12
0
 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();
 }
Ejemplo n.º 13
0
 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\"");
 }