CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1

Hybrid View

  1. #1
    Join Date
    Aug 2005
    Posts
    6

    Vbscript: Get Drive Letter of USB Removable Disk

    I have to get the drive letter of a specific model, based on DeviceID I believe, of a USB Removable disk drive (thumbdrive that shows up as a Removable Disk; not a HDD). Can anyone give any insight on how to do this? It only needs to work on XP Pro SP2. Thanks.


    For interest, here's the code that gets a specific model USB HDD (Model: "HTS54104 0G9AT00")
    Code:
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    
    Set colDiskDrives = objWMIService.ExecQuery("SELECT * FROM Win32_DiskDrive WHERE InterfaceType = 'USB'")
     
    For Each objDrive In colDiskDrives
    
        If Instr(1,objDrive.Caption, "HTS54104 0G9AT00") > 0 Then
    
    	strDeviceID = Replace(objDrive.DeviceID, "\", "\\")
    	Set colPartitions = objWMIService.ExecQuery ("ASSOCIATORS OF {Win32_DiskDrive.DeviceID=""" & strDeviceID & """} WHERE AssocClass = " & "Win32_DiskDriveToDiskPartition")
     
    	For Each objPartition In colPartitions
    
    		Set colLogicalDisks = objWMIService.ExecQuery("ASSOCIATORS OF {Win32_DiskPartition.DeviceID=""" & objPartition.DeviceID & """} WHERE AssocClass = " & "Win32_LogicalDiskToPartition")
     
    		For Each objLogicalDisk In colLogicalDisks
    			TargetPath = objLogicalDisk.DeviceID
    		Next
    	Next
        End If
    
    Next
    
    Wscript.Echo "USB Drive mounted at " & TargetPath
    Last edited by enternaL; December 8th, 2006 at 04:12 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured