2,726
社区成员
发帖
与我相关
我的任务
分享
VFP9.0,把下面代码放到你的 Combo1 控件的 Init 事件:
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
然后再加个 Timer 控件,
此控件的 Interval 值为1000,意思是1秒执行一行
此控件的 Timer 事件代码为:
This.Enabled= .F.
Thisform.Combo1.Init()
This.Enabled= .T.
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
--------------------
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