3

I’m trying to make a simple program. Here’s what I need to do in c#.

Drive letters used below are an example these will be selected by user from a drop down box.

-Select a hard drive (C:) This is a drop down.

-Find Fat32 (system) Partition on that drive. I'm assuming get the specific device ID from (C:) Then Search that Device ID for partition with info field (System) or Formatted as (Fat32)

-Assign a letter to that Fat32(system) partition (w:)

-Run CMD “bcdboot C:\Windows /s w: /f UEFI”

-Report output from cmd if it worked or failed

-Unnassign Letter (w:) from the partition.

Here’s what iv done so far I figure I need to get the disk drives device ID but not sure what to do from here.

-------------------------------------------------------------------------------------------------
///Get list of Drives to a ComboBox
foreach (var Drives in Environment.GetLogicalDrives())
            {
                DriveInfo DriveInf = new DriveInfo(Drives);
                if (DriveInf.IsReady == true)
                {
                    var DriveInfo = DriveInf.Name + "     " + DriveInf.VolumeLabel;
                    DriveSelection_ddbox.Items.Add(DriveInfo);
                }
            }

-------------------------------------------------------------------------------------------------

///List Device Info In a Text Box

var DriveSelected = DriveSelection_ddbox.SelectedItem.ToString().Substring(0, 3);

DriveInfo driveInfo = new DriveInfo(DriveSelected);

var DriveLetter = DriveSelection_ddbox.SelectedItem.ToString().Substring(0, 1);

ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"" + DriveLetter + ":\"");
disk.Get();

Drive_info.Text = "Drive Letter \r" + DriveSelected + "\r\rDrive Lable \r" + driveInfo.VolumeLabel +"\r\rDrive ID \r" + disk["VolumeSerialNumber"].ToString() + "\r\rDrive Size \r" + driveInfo.TotalSize;

-------------------------------------------------------------------------------------------------

///Here is where I need to figure out how to find the fat32(system Partition and assign a letter to it.

var AssignedDriveLetter = "w:";

///Select the partition and assign letter (AssignedDriveLetter)

-------------------------------------------------------------------------------------------------

//run CMD
string strCmdText;
strCmdText= "bcdboot " + DriveSelected + "Windows /s " + AssignedDriveLetter + ": /f UEFI";
System.Diagnostics.Process.Start("CMD.exe",strCmdText);

//Not sure how but get output from the cmd into a text box

-------------------------------------------------------------------------------------------------

/// CMD completed properly now unmount the letter

//unmount (w:\)



ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
coolshrimp
  • 101
  • 5
  • 1
    I've removed the `[visual-studio]` tag because this question isn't about the Visual Studio application. – ProgrammingLlama Sep 01 '20 at 09:20
  • For enumerating partitions on a disk, you can take a look at [this question](https://stackoverflow.com/questions/6575727/list-all-partitions-on-disk), and for capturing your spawned process' output, [this](https://stackoverflow.com/questions/186822/capturing-console-output-from-a-net-application-c) might be helpful. – vonludi Sep 01 '20 at 09:29

0 Answers0