VFP 怎么获取 可移动磁盘列表

VFP 怎么获取 可移动磁盘列表

VFP 如何获取 可移动磁盘列表
请教 VFP 下能获取 可移动磁盘列表吗?
谢谢!

------解决思路----------------------
Local  lnI, drvName, drvType ,mydri
mydri=""
for lni=1 to 25
drvname=chr(64+lni)+": "
drvtype=drivetype(drvname)
do case
case drvtype=1
driname="驱动器 " + drvname + "无类型"
case drvtype=2
driname="驱动器 " + drvname + "是一个软盘驱动器"
case drvtype = 3
driname="驱动器 " + drvname + "是一个硬盘驱动器"
case drvtype = 4
driname="驱动器 " + drvname + "是一个可移去式驱动器或网络驱动器"
case drvtype = 5
driname="驱动器 " + drvname + "是一个CD-ROM驱动器"
case drvtype=6
driname="驱动器 " + drvname + "是一个RAM 盘"
endcase
mydri=mydri+iif(directory(drvname),chr(13)+chr(10)+driname,"")
endfor
messagebox(mydri)

------解决思路----------------------
WIN API WIMI-获取U盘盘符
*-----------------------
* VFP9.0

Clear
m.loWMI = Getobject("winmgmts:\\.\root\cimv2")
m.loDisks = m.loWMI.ExecQuery([Select * From Win32_DiskDrive Where InterfaceType="USB"])
m.loParts = m.loWMI.ExecQuery([Select * From Win32_LogicalDiskToPartition])
For Each m.loDisk In m.loDisks
? 'USB 设备(' + m.loDisk.Caption + ')分配的盘符:'
m.lcDevID = 'Disk #' + Transform(m.loDisk.Index)
For Each m.loPart In m.loParts
If At(m.lcDevID, m.loPart.Antecedent) > 0
?? " " + Strextract(m.loPart.Dependent, [DeviceID="], ["], 1)
Endif
Endfor
Endfor
--------------------
*-- VFP9.0  以下代码可以放到 Combobox 的 Init 或 DropDown 事件中

This.Clear
m.loWMI = Getobject("winmgmts:\\.\root\cimv2")
m.loDisks = m.loWMI.ExecQuery([Select * From Win32_DiskDrive Where InterfaceType="USB"])
m.loParts = m.loWMI.ExecQuery([Select * From Win32_LogicalDiskToPartition])
For Each m.loDisk In m.loDisks
m.lcDevID = 'Disk #' + Transform(m.loDisk.Index)
For Each m.loPart In m.loParts
If At(m.lcDevID, m.loPart.Antecedent) > 0
This.AddItem(Strextract(m.loPart.Dependent, [DeviceID="], ["], 1)+' 容量:'+Transform(Diskspace(Strextract(m.loPart.Dependent, [DeviceID="], ["], 1),1)/1024/1024/1024)+'G')
Endif
Endfor
Endfor
Release m.loWMI
--------------------
Create Cursor diskinfo1 (DiskName C(30),DiskIndex I,DiskInterfaceType C(50))
oWMI=Getobject( 'winmgmts:' )
oItems=oWMI.ExecQuery('Select * From Win32_DiskDrive Where InterfaceType="USB"')
For Each oItem In oItems
Insert Into diskinfo1 Values (oItem.Caption,oItem.Index,oItem.InterfaceType)
Endfor

Create Cursor diskinfo2 (Antecedent C(200),Dependent C(200))
*oWMI=Getobject( 'winmgmts:' )
oItems=oWMI.ExecQuery('select * from Win32_LogicalDiskToPartition')
For Each oItem In oItems
Insert Into diskinfo2 Values (oItem.Antecedent,oItem.Dependent)
Endfor

Select Substr(A.Dependent,At(["],A.Dependent,1)+1,2) As U盘盘符 From diskinfo2 A Inner Join diskinfo1 B ;
On Val(Substr(A.Antecedent,At([#],A.Antecedent,1)+1,1))=B.DiskIndex


-------------------
* VFP6.0
Create Cursor diskinfo1 (DiskName C(30),DiskIndex I,DiskInterfaceType C(50))
oWMI1=Createobject("WbemScripting.SWbemLocator")
oWMI=oWMI1.ConnectServer(".", "root\cimv2")
oItems=oWMI.ExecQuery('select * from Win32_DiskDrive')
For Each oItem In oItems
Insert Into diskinfo1 Values (oItem.Caption,oItem.Index,oItem.InterfaceType)
Endfor

Create Cursor diskinfo2 (Antecedent C(200),Dependent C(200))
*oWMI=Getobject( 'winmgmts:' )
oItems=oWMI.ExecQuery('select * from Win32_LogicalDiskToPartition')
For Each oItem In oItems
Insert Into diskinfo2 Values (oItem.Antecedent,oItem.Dependent)
Endfor

Select Substr(A.Dependent,At(["],A.Dependent,1)+1,2) As U盘盘符 From diskinfo2 A Inner Join diskinfo1 B ;
On Val(Substr(A.Antecedent,At([#],A.Antecedent,1)+1,1))=B.DiskIndex Where B.DiskInterfaceType="USB"

--------------------
VFP9.0

VB codeCreate Cursor diskinfo (DeviceID C(30),Description C(50),Drivetype I)
oWMI = Getobject( 'winmgmts:' )
oItems = oWMI.ExecQuery( 'select * from Win32_LogicalDisk' )
For Each oItem In oItems
    Insert Into diskinfo Values (oItem.DeviceID,oItem.Description,oItem.Drivetype)
Endfor
Locate
Browse

-------------------
#Define MAX_PATH 260
Do Declare
Create Cursor csDosDevices (drvletter C(2),drvtype I,targetpath C(250))
Local cDrives,nBufsize,cDrvLetter,ch,cTargetPath
cDrives = Replicate(Chr(0),250)
nBufsize = GetLogicalDriveStrings(Len(cDrives),@cDrives)
cDrives = Padr(cDrives,nBufsize)
cDrvLetter=""
For nBufsize=1 To Len(cDrives)
ch = Substr(cDrives,nBufsize,1)
If ch = Chr(0)
cDrvLetter=Padr(cDrvLetter,2)
cTargetPath = Replicate(Chr(0),MAX_PATH)
= QueryDosDevice(cDrvLetter,@cTargetPath,Len(cTargetPath))
cTargetPath = Strtran(cTargetPath,Chr(0),"")
Insert Into csDosDevices Values (cDrvLetter,GetDriveType(cDrvLetter),cTargetPath)
cDrvLetter = ""
Else
cDrvLetter = cDrvLetter + m.ch
Endif
Next
Go Top
Browse Normal Nowait
Procedure Declare
Declare Integer GetDriveType In kernel32 String nDrive
Declare Integer GetLogicalDriveStrings In kernel32 Integer nBufferLength,String @lpBuffer
Declare Integer QueryDosDevice In kernel32 String lpDeviceName,String @lpTargetPath,Integer ucchMax
Endproc

-------------------

Public DriName
mydri =' '
Declare Integer GetLogicalDriveStrings In kernel32 Intege nBufferLength,String @ lpBuffer
Declare Integer GetDriveType In kernel32 String nDrive
AIIDrive=Replicate(' ',108)
=GetLogicalDriveStrings(Len(AIIDrive),@AIIDrive)
AIIDrive=Allt(AIIDrive)
For i=1 To Len(AIIDrive)/4
DriNameTmp=Substr(AIIDrive,i*4-3,2)
NDType=GetDriveType(DriNameTmp)
Do Case
Case NDType=2 And (DriNameTmp='A:' Or DriNameTmp='B:' Or DriNameTmp='a:' Or DriNameTmp='b:')
DriType='软驱'
Case NDType=2 And (DriNameTmp<>'A:' And DriNameTmp<>'B:' And DriNameTmp<>'a:' And DriNameTmp<>'b:')
DriType='U盘'
mydri=mydri+DriNameTmp+' '+DriType
Case NDType=3
DriType='硬盘'
Case NDType=5
DriType='光驱'
Endc
Endf
Wait Window mydri