question

OSD-4642 avatar image
0 Votes"
OSD-4642 asked ·

Disk Detection and Drive Leeters Assignment in VB.Net

Hi,

Currently I am using Diskpart (Windows command line utility) to manage disks and assign drive letters.
Disk 0 is present almost 99.99% scenarios, however, I need to check for the disk 1 and disk 2 all the time.
If disk 1 is present, assign letter 'Z' to partition 1 and 'X' to partition 2 (if exists). Otherwise, check if disk 2 is present and if yes assign letter 'M' to partition 1 and so on.. as in below screenshot.
Can same check /configured using VB.Net?

46641-image.png


dotnet-visual-basicdotnet-standard
image.png (24.7 KiB)
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

WayneAKing-0228 avatar image
0 Votes"
WayneAKing-0228 answered ·
·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

XingyuZhao-MSFT avatar image
1 Vote"
XingyuZhao-MSFT answered ·

Hi @OSD-4642 ,
You can also try using Process class to execute the Diskpart command.

         Dim p As Process = New Process()
         p.StartInfo.UseShellExecute = False
         ' Redirect the results on screen.
         p.StartInfo.RedirectStandardOutput = True
         p.StartInfo.FileName = "C:\Windows\System32\diskpart.exe"
         p.StartInfo.RedirectStandardInput = True
         p.Start()
         p.StandardInput.WriteLine("list disk")
         p.StandardInput.WriteLine("exit")
         Dim output As String = p.StandardOutput.ReadToEnd()
    
         If output.Contains("Disk 1") Then
             p.Start()
             p.StandardInput.WriteLine("select disk 1")
             ' Assign letter 'Z' to partition 1.
             p.StandardInput.WriteLine("assign ...")
             p.StandardInput.WriteLine("exit")
             output = p.StandardOutput.ReadToEnd()
             p.WaitForExit()
             Console.WriteLine(output)
         End If
         p.WaitForExit()
         Console.ReadLine()

Hope it could be helpful.

Best Regards,
Xingyu Zhao


If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.