???最近看到浪潮的獵鷹服務器管理軟件,其中可以對遠程服務器的CPU和內存使用率進行實時監視,就像任務管理器那樣繪制一個報表。我推斷他要么是使用SNMP協議從客戶機拿到數據之后在傳遞給管理器,要么就是使用Windows提供的某些System Performence COM組件來抓數據。
???查MSDN,上有一個System Monitor的例子。居然是用VBScript來調一調控制面板-〉管理工具-〉性能-〉系統監視器。既然是用HTML嵌VBScript,那轉換為應用程序到也方便,將文件后綴名改為.hta,即以HTML Application方式打開,由MSHTA.exe來解釋執行就可以了。
???下面的程序就是從命令行中獲取要監視的計算機IP地址后,啟動System Monitor,監視之。
<HTML>
<HEAD>
<HTA:APPLICATION?ID="oHTA"
????APPLICATIONNAME
="myApp">
???
<meta?http-equiv="Content-Type"?content="text/html;?charset=gb2312"?>
???
</HEAD>
????
<BODY?BGCOLOR="#C0C0C0">
????????
<SCRIPT?LANGUAGE="VBScript">
??
Sub?Monitor_OnCounterAdded(index)
????Monitor.Counters.Item(
1).Width?=?8
??
End?Sub
????????
</SCRIPT>
????????
<OBJECT?CLASSID="clsid:C4D2D8E0-D1DD-11CE-940F-008029004347"?ID="Monitor"?HEIGHT="80%"?WIDTH="100%"
????????????VIEWASTEXT
>
????????
</OBJECT>
????????
<SCRIPT?LANGUAGE="VBScript">
????????
??
Sub?Window_OnLoad
????
On?Error?Resume?Next
????Monitor.ShowValueBar?
=?True
????Monitor.ShowHorizontalGrid?
=?True
????
????Arg?
=?Trim(?oHTA.commandLine?)

????IPArgPos?
=?InStr(2,?Arg,?"""",?1)
????IPArg?
=?Trim(?right(?Arg,?len(Arg)-IPArgPos)?)
????
????IPStrings?
=?split(?IPArg,?"?",?-1,?1?)

????
for?i?=?0?to?uBound(IPStrings)
????Monitor.Counters.Add(?
"\\"?+?IPStrings(i)?+?"\Processor(_Total)\%?Processor?Time"?)
????Monitor.Counters.Add(?
"\\"?+?IPStrings(i)?+?"\Memory\Available?MBytes"?)
????Monitor.Counters.Add(?
"\\"?+?IPStrings(i)?+?"PhysicalDisk(_Total)\Avg.?Disk?Queue?Length"?)
????Monitor.Counters.Add(?
"\\"?+?IPStrings(i)?+?"\LogicalDisk(_Total)\%?Free?Space"?)
????Monitor.Counters.Add(?
"\\"?+?IPStrings(i)?+?"\Network?Interface(*)\Bytes?Total/sec"?)
????
Next

????
'Monitor.Counters.Add(?"\Process(*)\%?Processor?Time")
????Monitor.DisplayType=sysmonLineGraph
????Monitor.GraphTitle
=?"計算機系統性能監視"
??
End?Sub
??
????????
</SCRIPT>
????
</BODY>
</HTML>
???不知道大家有沒有使用過COM組件將這樣的東西嵌到C++程序中。如果有的話,不妨發表上來看看。