以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  如何在下列代码中加入自动识别U盘?因为不同电脑U盘盘符不一样。  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=25931)

--  作者:lyfxybc
--  发布时间:2012/11/20 11:55:00
--  如何在下列代码中加入自动识别U盘?因为不同电脑U盘盘符不一样。

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

 

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

 

 


--  作者:lin_hailun
--  发布时间:2012/11/20 12:06:00
--  
 用对话框选择路径行不?

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

--  作者:lin_hailun
--  发布时间: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
--  发布时间: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