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.