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


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

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

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


加好友 发短信
等级:六尾狐 帖子:1294 积分:9852 威望:0 精华:0 注册:2012/9/19 21:13:00
如何在下列代码中加入自动识别U盘?因为不同电脑U盘盘符不一样。  发帖心情 Post By:2012/11/20 11:55:00 [只看该作者]

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

 

Dim ex as New Exporter
ex
.SourceTableName = "订单" '指定导出
ex
.filepath = "c:\Data\订单.mdb" '指定目标文件
ex
.Export() '开始

 

 


 回到顶部
帅哥哟,离线,有人找我吗?
lin_hailun
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | 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
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | 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
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | 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

 回到顶部