示例#1
0
        private void AddVhdToBootMenu()
        {
            string entryDescription  = "VHDNBOM OS Image";
            string copyCurrentOutput = this.fileSystemHelper.ExecuteBcdeditCommand($"/copy {{current}} /d \"{entryDescription}\"", logger);

            if (copyCurrentOutput != null && copyCurrentOutput.LastIndexOf('{') > 0 && copyCurrentOutput.LastIndexOf('}') > copyCurrentOutput.LastIndexOf('{'))
            {
                int    beginGuidIndex    = copyCurrentOutput.LastIndexOf('{');
                int    endGuidIndex      = copyCurrentOutput.LastIndexOf('}');
                string newEntryGuidValue = copyCurrentOutput.Substring(beginGuidIndex + 1, endGuidIndex - beginGuidIndex - 1);
                logger.LogDebug($"Created new boot menu entry '{entryDescription}' with id {newEntryGuidValue}");

                Guid newEntryId             = Guid.Parse(newEntryGuidValue);
                char vhdLocationDriveLetter = migrationData.VhdFileDestinationFolder[1] == ':' ? migrationData.VhdFileDestinationFolder[0] : migrationData.OperatingSystemDriveLetter;
                fileSystemHelper.ExecuteBcdeditCommand($"/set {{{newEntryId}}} osdevice vhd=[{vhdLocationDriveLetter}:]{this.vhdBcdeditEntryPath}", logger);
                fileSystemHelper.ExecuteBcdeditCommand($"/set {{{newEntryId}}} device vhd=[{vhdLocationDriveLetter}:]{this.vhdBcdeditEntryPath}", logger);
            }
            else
            {
                throw new ArgumentException("New boot entry has not been created for unknown reasons. Please check if bcdedit is working correctly on your system.");
            }
        }