得到memory状态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 TypePrivate Declare Sub GlobalMemoryStatus Lib "kernel32" _ (lpBuffer As MEMORYSTATUS)Private Sub Form_Load() Dim MS As MEMORYSTATUS
得到计算机名 Private Declare Function GetComputerName Lib "kernel32" _ Alias "GetComputerNameA" _ (ByVal lpBuffer As String, _ nSize As Long) As Long得到主板信息 Private Const LVM_FIRST As Long = &H1000 Private Const LVM_SETCOLUMNWIDTH As Long = (LVM_FIRST + 30) Private Const LVSCW_AUTOSIZE As Long = -1 Private Const LVSCW_AUTOSIZE_USEHEADER As Long = -2Private Declare Function SendMessage Lib "user32" _ Alias "SendMessageA" _ (ByVal hwnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ lParam As Any) As Long Private Sub Form_Load() With ListView1 .ListItems.Clear .ColumnHeaders.Clear .ColumnHeaders.Add , , "Product" .ColumnHeaders.Add , , "Manufacturer" .View = lvwReport .Sorted = False End With
Command1.Caption = "BaseBoard Info"End Sub Private Sub Command1_Click() ListView1.ListItems.Clear Call wmiBaseBoardInfo Call lvAutosizeControl(ListView1)
End Sub Private Sub lvAutosizeControl(lv As ListView) Dim col2adjust As Long '/* Size each column based on the maximum of '/* EITHER the columnheader text width, or, '/* if the items below it are wider, the '/* widest list item in the column For col2adjust = 0 To lv.ColumnHeaders.Count - 1
Call SendMessage(lv.hwnd, _ LVM_SETCOLUMNWIDTH, _ col2adjust, _ ByVal LVSCW_AUTOSIZE_USEHEADER) Next
End Sub Private Sub wmiBaseBoardInfo() Dim BaseBoardSet As SWbemObjectSet Dim bb As SWbemObject Dim itmx As ListItem
Set BaseBoardSet = GetObject("winmgmts:{impersonationLevel=impersonate}"). _ InstancesOf("Win32_BaseBoard")
On Local Error Resume Next
For Each bb In BaseBoardSet
Set itmx = ListView1.ListItems.Add(, , bb.Product) itmx.SubItems(1) = bb.Manufacturer
NextEnd Sub
你的分不多,问题可不少监视 CPU 使用情况的例子 http://www.sijiqing.com/vbgood/download/code/CPU.zip 显示 CPU 的使用情况 http://www.sijiqing.com/vbgood/download/code/CPUUsage.zipDeclare Function GetTickCount Lib "kernel32" Alias "GetTickCount" () As Long 说明 用于获取自windows启动以来经历的时间长度(毫秒) 返回值 Long,以毫秒为单位的windows运行时间 Declare Sub GetSystemTime Lib "kernel32" Alias "GetSystemTime" (lpSystemTime As SYSTEMTIME) 说明 在一个SYSTEMTIME中载入当前系统时间,这个时间采用的是“协同世界时间”(即UTC,也叫做GMT)格式 参数表 参数 类型及说明 lpSystemTime SYSTEMTIME,随同当前时间载入的结构
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 TypePrivate Declare Sub GlobalMemoryStatus Lib "kernel32" _
(lpBuffer As MEMORYSTATUS)Private Sub Form_Load() Dim MS As MEMORYSTATUS
MS.dwLength = Len(MS)
GlobalMemoryStatus MS
'divide the memory variables by 1024 (nkb)
'to obtain the size in kilobytes
Label1(0).Caption = Format$(MS.dwMemoryLoad, "###,###,###,###") & " % used"
Label1(1).Caption = Format$(MS.dwTotalPhys / 1024, "###,###,###,###") & " Kbyte"
Label1(2).Caption = Format$(MS.dwAvailPhys / 1024, "###,###,###,###") & " Kbyte"
Label1(3).Caption = Format$(MS.dwTotalPageFile / 1024, "###,###,###,###") & " Kbyte"
Label1(4).Caption = Format$(MS.dwAvailPageFile / 1024, "###,###,###,###") & " Kbyte"
Label1(5).Caption = Format$(MS.dwTotalVirtual / 1024, "###,###,###,###") & " Kbyte"
Label1(6).Caption = Format$(MS.dwAvailVirtual / 1024, "###,###,###,###") & " Kbyte"End Sub
Private Sub Command1_Click() Unload Me
End Sub
Private Declare Function GetComputerName Lib "kernel32" _
Alias "GetComputerNameA" _
(ByVal lpBuffer As String, _
nSize As Long) As Long得到主板信息
Private Const LVM_FIRST As Long = &H1000
Private Const LVM_SETCOLUMNWIDTH As Long = (LVM_FIRST + 30)
Private Const LVSCW_AUTOSIZE As Long = -1
Private Const LVSCW_AUTOSIZE_USEHEADER As Long = -2Private Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Private Sub Form_Load() With ListView1
.ListItems.Clear
.ColumnHeaders.Clear
.ColumnHeaders.Add , , "Product"
.ColumnHeaders.Add , , "Manufacturer"
.View = lvwReport
.Sorted = False
End With
Command1.Caption = "BaseBoard Info"End Sub
Private Sub Command1_Click() ListView1.ListItems.Clear
Call wmiBaseBoardInfo
Call lvAutosizeControl(ListView1)
End Sub
Private Sub lvAutosizeControl(lv As ListView) Dim col2adjust As Long '/* Size each column based on the maximum of
'/* EITHER the columnheader text width, or,
'/* if the items below it are wider, the
'/* widest list item in the column
For col2adjust = 0 To lv.ColumnHeaders.Count - 1
Call SendMessage(lv.hwnd, _
LVM_SETCOLUMNWIDTH, _
col2adjust, _
ByVal LVSCW_AUTOSIZE_USEHEADER) Next
End Sub
Private Sub wmiBaseBoardInfo() Dim BaseBoardSet As SWbemObjectSet
Dim bb As SWbemObject
Dim itmx As ListItem
Set BaseBoardSet = GetObject("winmgmts:{impersonationLevel=impersonate}"). _
InstancesOf("Win32_BaseBoard")
On Local Error Resume Next
For Each bb In BaseBoardSet
Set itmx = ListView1.ListItems.Add(, , bb.Product)
itmx.SubItems(1) = bb.Manufacturer
NextEnd Sub
http://www.sijiqing.com/vbgood/download/code/CPU.zip
显示 CPU 的使用情况
http://www.sijiqing.com/vbgood/download/code/CPUUsage.zipDeclare Function GetTickCount Lib "kernel32" Alias "GetTickCount" () As Long
说明
用于获取自windows启动以来经历的时间长度(毫秒)
返回值
Long,以毫秒为单位的windows运行时间 Declare Sub GetSystemTime Lib "kernel32" Alias "GetSystemTime" (lpSystemTime As SYSTEMTIME)
说明
在一个SYSTEMTIME中载入当前系统时间,这个时间采用的是“协同世界时间”(即UTC,也叫做GMT)格式
参数表
参数 类型及说明
lpSystemTime SYSTEMTIME,随同当前时间载入的结构