Foxtable(狐表)用户栏目专家坐堂 → 如何在下列代码中加入自动识别U盘?因为不同电脑U盘盘符不一样。


  共有10036人关注过本帖树形打印复制链接

主题:如何在下列代码中加入自动识别U盘?因为不同电脑U盘盘符不一样。

帅哥哟,离线,有人找我吗?
lin_hailun
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:狐神 帖子:6708 积分:34304 威望:0 精华:11 注册:2012/8/18 23:10:00
  发帖心情 Post By:2012/11/20 12:06:00 [显示全部帖子]

 用对话框选择路径行不?

http://www.foxtable.com/help/topics/0329.htm

 回到顶部
帅哥哟,离线,有人找我吗?
lin_hailun
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:狐神 帖子:6708 积分:34304 威望:0 精华:11 注册:2012/8/18 23:10:00
  发帖心情 Post By:2012/11/20 12:13:00 [显示全部帖子]

从论坛拷贝过来一段代码

Dim s As String = "USB*"

Dim GetUSBPath As String
Dim USBDevices, USBDevice, USBDiskPartitions, USBDiskPartition, LogicalUSBDisks, LogicalUSBDisk , objWMIService As Object
objWMIService = GetObject("winmgmts:\\.\root\cimv2")
USBDevices = objWMIService.execquery("Select * From Win32_DiskDrive where InterfaceType='USB'")
For Each USBDevice In USBDevices
    If USBDevice.PNPDeviceID Like s Then
        USBDiskPartitions = objWMIService.execquery("Associators of {Win32_DiskDrive.DeviceID='" & USBDevice.DeviceId & "'} where AssocClass = Win32_DiskDriveToDiskPartition")
        For Each USBDiskPartition In USBDiskPartitions
            LogicalUSBDisks = objWMIService.execquery("Associators of {Win32_DiskPartition.DeviceID='" & USBDiskPartition.DeviceId & "'} where AssocClass = Win32_LogicalDiskToPartition")
            For Each LogicalUSBDisk In LogicalUSBDisks
                GetUSBPath = GetUSBPath & "|" & LogicalUSBDisk.DeviceId
                msgbox(GetUSBPath.TrimStart("|"))
            Next
        Next
        Exit For
    End If
Next

 回到顶部
帅哥哟,离线,有人找我吗?
lin_hailun
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:狐神 帖子:6708 积分:34304 威望:0 精华:11 注册:2012/8/18 23:10:00
  发帖心情 Post By:2012/11/20 12:16:00 [显示全部帖子]

Dim s As String = "USB*"

Dim USBDevices, USBDevice, USBDiskPartitions, USBDiskPartition, LogicalUSBDisks, LogicalUSBDisk , objWMIService As Object
objWMIService = GetObject("winmgmts:\\.\root\cimv2")
USBDevices = objWMIService.execquery("Select * From Win32_DiskDrive where InterfaceType='USB'")
For Each USBDevice In USBDevices
    If USBDevice.PNPDeviceID Like s Then
        USBDiskPartitions = objWMIService.execquery("Associators of {Win32_DiskDrive.DeviceID='" & USBDevice.DeviceId & "'} where AssocClass = Win32_DiskDriveToDiskPartition")
        For Each USBDiskPartition In USBDiskPartitions
            LogicalUSBDisks = objWMIService.execquery("Associators of {Win32_DiskPartition.DeviceID='" & USBDiskPartition.DeviceId & "'} where AssocClass = Win32_LogicalDiskToPartition")
            For Each LogicalUSBDisk In LogicalUSBDisks                
                msgbox(LogicalUSBDisk.DeviceId)
            Next
        Next
        Exit For
    End If
Next

 回到顶部