星期四, 九月 14, 2006

(VB.NET)获取可用内存大小

Imports System

Imports System.Management

Module Module1

Public Sub Main()

Dim strComputer As String = "." , i, intValue As Integer

Dim colItems, objWMIService, objItem

objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

'重复执行 20 次检查

For i = 1 To 20

'产生内存快照

colItems = objWMIService.ExecQuery("Select * From Win32_PerfRawData_PerfOS_Memory")

For Each objItem In colItems

intValue = objItem.AvailableMbytes

Console.WriteLine("可用内存大小 (MB): " & intValue )

'延时 5 秒

Threading.Thread.Sleep(5000)

Next

Next

End Sub

End Module

没有评论: