SoFunction
Updated on 2025-03-10

VBScript code to find device name based on drive letter


On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = ( _
    "associators of {win32_logicaldisk.deviceid='G:'} WHERE ResultClass=Win32_DiskPartition")
For Each objItem in colItems
 TargetIndex =
 Set Items = ( _
  "SELECT * FROM Win32_DiskDrive Where DeviceID Like '%" & & "'",,48)
 For Each Item in Items
   "Model: " &
 Next

Next