请教高手,vb如何获得硬盘信息!
包括容量,剩余容量,已用容量,文件系统,;硬盘类型等麻烦讲清除一点!谢谢! --------------------编程问答-------------------- 查询wmi的win32_diskdrive、Win32_LogicalDisk 等相关类的信息。 --------------------编程问答-------------------- 能说清楚一点吗?
--------------------编程问答-------------------- sub DDD()
Dim oAdapters As Object, oAdapter As Object
On Error Resume Next
Set oAdapters = GetObject("winmgmts:").ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
For Each oAdapter In oAdapters
Text1 = "MAC ADDRESS: " & Replace(oAdapter.MacAddress, ":", " ") & vbCrLf
Exit For
Next
'用WMI对象列出系统所有磁盘:----Instance.vbs----
Dim objDisk
For Each objDisk In GetObject("winmgmts:").InstancesOf("Win32_LogicalDisk")
Text1 = Text1 + objDisk.DeviceId & " "
Next
Text1 = Text1 + vbCrLf
'获得物理内存的容量:-----physicalMemory.vbs-----
Dim strComputer: strComputer = "."
Set wbemServices = GetObject("winmgmts:\\" & strComputer)
Set wbemObjectSet = wbemServices.InstancesOf("Win32_LogicalMemoryConfiguration")
For Each wbemObject In wbemObjectSet
Text1 = Text1 + "物理内存 (MB): " & CInt(wbemObject.totalPhysicalMemory / 1024) + vbCrLf
Next
'CPU的序列号:---CPUID.vbs---
Dim cpuInfo As String: cpuInfo = ""
Set moc = GetObject("Winmgmts:").InstancesOf("Win32_Processor")
For Each mo In moc
cpuInfo = CStr(mo.ProcessorId)
Text1 = Text1 + "CPU SerialNumber is : " & cpuInfo + vbCrLf
Next
'硬盘型号:---HDID.vbs---
Dim HDid
Set moc = GetObject("Winmgmts:").InstancesOf("Win32_DiskDrive")
For Each mo In moc
HDid = mo.Model
Text1 = Text1 + "硬盘型号为:" & HDid + vbCrLf
Next
end sub --------------------编程问答-------------------- 楼上大哥,这个东西可以使用API数, --------------------编程问答-------------------- 这么简单了用吧,为什么你要用API呢,'硬盘型号
Dim HDid
Set moc = GetObject("Winmgmts:").InstancesOf("Win32_DiskDrive")
For Each mo In moc
HDid = mo.Model
Text1 = Text1 + "硬盘型号为:" & HDid + vbCrLf
Next --------------------编程问答-------------------- 非要用也有读取磁盘序列号
Private Declare Function GetVolumeInformation& Lib "kernel32" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal pVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long)
--------------------编程问答-------------------- 。。。。。。。 --------------------编程问答-------------------- 以上说的太麻烦,如果你用的是VB6.0,可以用文件系统对象(FileSystemObject)来获得你需要的硬盘信息.例如,你可以使用Drive对象的相关属性来得到硬盘信息. --------------------编程问答-------------------- 能用API实现尽量用API 速度和安全性都会高些 --------------------编程问答-------------------- 这个FileSystemObject东西很多系统都不带,还是尽量绿色好,绿色不影响系统的速度。
--------------------编程问答-------------------- FileSystemObject带的,呵呵,我也来牛逼一把,前几天借用了csdn上的几行代码,很有效,就拿来分享了。
Dim Fso As New FileSystemObject, drv As Drive, s As String
Set drv = Fso.GetDrive(Fso.GetDriveName("e:"))
s = "drive" & UCase("e:") & "_"
s = s & drv.VolumeName & vbCrLf
s = s & "total space" & FormatNumber(drv.TotalSize / 1024 / 1024, 0)
s = s & "MB" & vbCrLf
s = s & "free space" & FormatNumber(drv.FreeSpace / 1024, 0)
s = s & "KB" & vnrclf
Debug.Print s
补充:VB , API