Get the PnP ID of USB thumdrive
-
Dear all, I have a problem on how to get the PnP ID of a USB Thumbdrive. I will get the driveletter of the thumbdrive, say "J" but not able to assoiciate the PnP ID of the USB device in that particular drive (ie J), instead the code given below is giving PnP ID of all the mounted thumbdrives I will be very thankful if someone can get me the solution code: Dim obj, objs, buf Set objs = GetObject("winmgmts:").InstancesOf("Win32_DiskDrive") Set objFSO = CreateObject("Scripting.FileSystemObject") Set colDrives = objFSO.Drives Dim drv As String drv = "J" For Each obj In objs For Each objDrive In colDrives buf = IIf((obj.InterfaceType = "USB") And (objDrive.DriveLetter = "J"), _ obj.PNPDeviceID, "") buf = "Model: " & obj.Model & vbCrLf buf = buf & "PnP Device ID: " & obj.PNPDeviceID & vbCrLf msgbox buf Next Next End Sub thank you Dinakara K CAIR Bangalore Dinakara K CAIR, Bangalore
-
Dear all, I have a problem on how to get the PnP ID of a USB Thumbdrive. I will get the driveletter of the thumbdrive, say "J" but not able to assoiciate the PnP ID of the USB device in that particular drive (ie J), instead the code given below is giving PnP ID of all the mounted thumbdrives I will be very thankful if someone can get me the solution code: Dim obj, objs, buf Set objs = GetObject("winmgmts:").InstancesOf("Win32_DiskDrive") Set objFSO = CreateObject("Scripting.FileSystemObject") Set colDrives = objFSO.Drives Dim drv As String drv = "J" For Each obj In objs For Each objDrive In colDrives buf = IIf((obj.InterfaceType = "USB") And (objDrive.DriveLetter = "J"), _ obj.PNPDeviceID, "") buf = "Model: " & obj.Model & vbCrLf buf = buf & "PnP Device ID: " & obj.PNPDeviceID & vbCrLf msgbox buf Next Next End Sub thank you Dinakara K CAIR Bangalore Dinakara K CAIR, Bangalore
Dinakara K wrote: buf = IIf((obj.InterfaceType = "USB") And (objDrive.DriveLetter = "J"), _ obj.PNPDeviceID, "") buf = "Model: " & obj.Model & vbCrLf buf = buf & "PnP Device ID: " & obj.PNPDeviceID & vbCrLf msgbox buf Try replacing the immediate If statement with a regular If statement. Every time you go through your For...Next loop its adding Dinakara K wrote: buf = "Model: " & obj.Model & vbCrLf buf = buf & "PnP Device ID: " & obj.PNPDeviceID & vbCrLf to your buf variable no matter what is returned by the IIF statement. Besides, buf = "Model: " & obj.Model & vbcrlf is replacing whatever you had you IIF statement return.