Have you read this thread?
using diskpart from vb ...
https://social.msdn.microsoft.com/Forums/vstudio/en-US/23d97079-4c51-4538-ab6e-013b1a562370/using-diskpart-from-vb-any-api-or-alternative-and-how-to-get-the-disk-id?forum=vbgeneral
- Wayne
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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?
Have you read this thread?
using diskpart from vb ...
https://social.msdn.microsoft.com/Forums/vstudio/en-US/23d97079-4c51-4538-ab6e-013b1a562370/using-diskpart-from-vb-any-api-or-alternative-and-how-to-get-the-disk-id?forum=vbgeneral
Hi @~OSD~ ,
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.