vb6.0中如何自动篇历系统的全部驱动器并获得全部信息?

如题所述

假如只是想列驱动器名,如下很简单的,网络驱动器映射后也一样能列出。
‘列出所有驱动器,不含A,B
Dim drv() As String
Dim sd As String
drv() = Split("C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z", ",")
For i = 0 To 23
sd = drv(i) & ":\"
If Dir(sd, vbDirectory) <> "" Then
comb.AddItem sd ’添加到列表中
End If
Next
温馨提示:内容为网友见解,仅供参考
第1个回答  2013-03-17
'
'这是一个获取系统主要信息的程序
'
Private Type SYSTEM_INFO
dwOemID As Long
dwPageSize As Long
lpMinimumApplicationAddress As Long
lpMaximumApplicationAddress As Long
dwActiveProcessorMask As Long
dwNumberOrfProcessors As Long
dwProcessorType As Long
dwAllocationGranularity As Long
dwReserved As Long
End Type
Private Type MEMORYSTATUS
dwLength As Long
dwMemoryLoad As Long
dwTotalPhys As Long
dwAvailPhys As Long
dwTotalPageFile As Long
dwAvailPageFile As Long
dwTotalVirtual As Long
dwAvailVirtual As Long
End Type
Const SM_CXSCREEN = 0
Const SM_CYSCREEN = 1
Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
Private Declare Function GetDiskFreeSpace Lib "kernel32" Alias "GetDiskFreeSpaceA" (ByVal lpRootPathName As String, lpSectorsPerCluster As Long, lpBytesPerSector As Long, lpNumberOfFreeClusters As Long, lpTtoalNumberOfClusters As Long) As Long
Private Declare Sub GlobalMemoryStatus Lib "kernel32" (lpBuffer As MEMORYSTATUS)
Private Declare Sub GetSystemInfo Lib "kernel32" (lpSystemInfo As SYSTEM_INFO)
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Private Declare Function WNetGetConnection Lib "mpr.dll" Alias "WNetGetConnectionA" (ByVal lpszLocalName As String, ByVal lpszRemoteName As String, cbRemoteName As Long) As Long
Dim sinfo As SYSTEM_INFO
Dim minfo As MEMORYSTATUS
Private Sub Combo1_Click()
Dim x As Long
Dim cl1 As Long
Dim cl2 As Long
Dim sec1 As Long
Dim byt1 As Long
Dim buff As String

buff = Combo1.Text + ":\"
x = GetDriveType(buff)
Select Case x
Case 2
Label1.Caption = "该驱动器是可移动驱动器"
Case 3
Label1.Caption = "该驱动器是固定驱动器"
Case 4
Label1.Caption = "该驱动器是网络驱动器"
Case 5
Label1.Caption = "该驱动器是CD-ROM驱动器"
Case 6
Label1.Caption = "该驱动器是RAMDISK驱动器"
Case Else
Label1.Caption = "该驱动器无效"
End Select
x = GetDiskFreeSpace(buff, sec1, byt1, cl1, cl2)
If x Then

Label2.Caption = "该驱动器总共容量 " + Format$(cl2, "##########0") + " 字节"
Label3.Caption = "该驱动器可用容量 " + Format$(cl1, "##########0") + " 字节"
Else
Label2.Caption = ""
Label3.Caption = ""
End If
End Sub

Private Sub Form_Load()
Dim x As Long
Dim buff As String

For i = 0 To 25
buff = Chr$(65 + i) + ":\"
x = GetDriveType(buff)
If x > 1 Then
Combo1.AddItem Chr$(65 + i)
End If
Next i
Combo1.Text = "C"
Combo1_Click
x = GetSystemMetrics(SM_CXSCREEN)
Label4.Caption = "显示器水平分辨率 " + Str$(x)
x = GetSystemMetrics(SM_CYSCREEN)
Label5.Caption = "显示器垂直分辨率 " + Str$(x)
Call GetSystemInfo(sinfo)

Select Case sinfo.dwProcessorType
Case 386
Case 486
Case 586
Label6.Caption = "计算机处理器类型 P5"
Case Else
End Select
Call GlobalMemoryStatus(minfo)
Label7.Caption = "物理内存总容量 " + Str$(minfo.dwTotalPhys) + " 字节"
Label8.Caption = "可用物理内存 " + Str$(minfo.dwAvailPhys) + " 字节"
Label10.Caption = "虚拟内存总容量 " + Str$(minfo.dwTotalVirtual) + " 字节"
Label11.Caption = "可用虚拟内存 " + Str$(minfo.dwAvailVirtual) + " 字节"
End Sub本回答被提问者采纳
相似回答