Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Hardware & Devices
  4. Get the PnP ID of USB thumdrive

Get the PnP ID of USB thumdrive

Scheduled Pinned Locked Moved Hardware & Devices
helptutorial
2 Posts 2 Posters 7 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dinakara K
    wrote on last edited by
    #1

    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

    Q 1 Reply Last reply
    0
    • D Dinakara K

      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

      Q Offline
      Q Offline
      quacks_a_lot
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups