ComputersUnlimited
IS-IT--Management
I am writing a program in VB 2019 where I need to know whether the system drive is a HDD or SSD. Is this possible and if so how?
Thank You
Thank You
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
[blue]Imports System.IO
Imports System.Management
Module Module2
Public Sub EnumPhysicalDriveTypes()
Dim scope = New ManagementScope("\\.\root\microsoft\windows\storage")
Dim searcher = New ManagementObjectSearcher("SELECT * FROM MSFT_PhysicalDisk")
Dim Type As String = ""
scope.Connect()
searcher.Scope = scope
Dim rootDrive As String = Path.GetPathRoot(Environment.SystemDirectory)
Dim queryObj As ManagementObject
For Each queryObj In searcher.Get()
Select Case queryObj("MediaType")
Case 1
Type = "Unspecified"
Case 3
Type = "HDD"
Case 4
Type = "SSD"
Case 5
Type = "SCM"
Case Else
Type = "Unspecified"
End Select
MsgBox("Device " & queryObj("DeviceID") & ": " & Type)
Next
searcher.Dispose()
End Sub
End Module[/blue]
[blue]Module Example
Public Enum Partitiontype
boot
system
End Enum
Public Function GetPartitionMediaType(ByVal Part As Partitiontype) As String
Dim strScope As String = "\\.\root\microsoft\windows\storage"
Dim PartType As String = ""
Dim DiskID As String = ""
Dim MediaType As String = ""
Select Case Part
Case Partitiontype.boot
PartType = "IsBoot"
Case Partitiontype.system
PartType = "IsSystem"
End Select
Dim searcher = New ManagementObjectSearcher(strScope, "SELECT * FROM MSFT_Partition WHERE " & PartType & "=TRUE")
For Each queryObj As ManagementObject In searcher.Get()
DiskID = queryObj("DiskNumber")
Next
searcher = New ManagementObjectSearcher(strScope, "SELECT * FROM MSFT_PhysicalDisk WHERE DeviceID = " & DiskID)
For Each queryObj As ManagementObject In searcher.Get()
Select Case queryObj("MediaType")
Case 1
MediaType = "Unspecified"
Case 3
MediaType = "HDD"
Case 4
MediaType = "SSD"
Case 5
MediaType = "SCM"
Case Else
MediaType = "Unspecified"
End Select
Next
GetPartitionMediaType = MediaType
End Function
End Module[/blue]
[blue] MsgBox("Boot drive is " & GetPartitionMediaType(Partitiontype.boot))
MsgBox("System drive is " & GetPartitionMediaType(Partitiontype.system))[/blue]