打印

[转帖] 监视相关

本主题由 mwpq 于 2007-11-7 09:00 关闭

监视相关

基准性能监视. j) E" L9 v; [) ~9 m# ]! J; z

& _1 C$ }. ?3 I3 f c0 G描述
& |7 u' g8 S$ Z使用加热的性能计数器和 SWbemRefresher 对象监视计算机上的三个性能计数器,并且将该数据保存到一个文本文件。需要 Windows XP 或 Windows Server 2003。' j5 q. n* A0 l6 O q/ j
脚本代码
5 S) d& T8 a7 Z6 pConst ForAppending = 8strComputer = "."Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")set objRefresher = CreateObject("WbemScripting.Swbemrefresher")Set objMemory = objRefresher.AddEnum _ (objWMIService, "Win32_PerfFormattedData_PerfOS_Memory").objectSetSet objDiskSpace = objRefresher.AddEnum _ (objWMIService, "Win32_PerfFormattedData_PerfDisk_LogicalDisk").objectSetSet objQueueLength = objRefresher.AddEnum _ (objWMIService, "Win32_PerfFormattedData_PerfNet_ServerWorkQueues").objectSetobjRefresher.RefreshSet objFSO = CreateObject("Scripting.FileSystemObject")Set objLogFile = objFSO.OpenTextFile _ ("c:\scripts\performance.csv", ForAppending, True)For I = 1 to 10 For each intAvailableBytes in objMemory objLogFile.Write(intAvailableBytes.AvailableMBytes) & "," Next For each intQueueLength in objDiskSpace objLogFile.Write(intQueueLength.CurrentDiskQueueLength) & "," Next For each intServerQueueLength in objQueueLength objLogFile.Write(intServerQueueLength.QueueLength) & "," Next objLogFile.Write VbCrLf Wscript.Sleep 10000 objRefresher.RefreshNextobjLogFile.Close配置信任关系属性更新日期: 2/17/2003
; q3 g+ _7 _& V" ^$ o
0 [/ r# w. a! K. i7 S2 m/ v0 O描述
" `4 V4 B" b1 g配置信任关系刷新和验证属性。需要 Windows Server 2003。
5 z. V- s, ]% a: s! i脚本代码4 O! K5 C$ ~& l
strComputer = "."Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & _ strComputer & "\root\MicrosoftActiveDirectory")Set colTrustList = objWMIService.ExecQuery _ ("Select * from Microsoft_TrustProvider")For Each objTrust in colTrustList objTrust.TrustListLifetime = 25 objTrust.TrustStatusLifetime = 10 objTrust.TrustCheckLevel = 1 objTrust.Put_Next创建永久事件消费程序更新日期: 2/17/2003
% |) U2 q/ L3 x6 e$ |& \# j- c$ _* h3 |- t& h
描述- x5 @: U: o) K3 c+ I' f+ y/ h
创建一个永久事件消费程序来监视服务状态中的改变。
8 Z9 n+ J1 u4 _; ^6 Y0 Y$ I0 m0 h脚本代码- i. k! V E9 z9 @. d
strComputer = "."Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\default")Set objConsumerType = objWMIService.get("SMTPEventConsumer")Set objConsumer = objConsumerType.SpawnInstance_objConsumer.Name = "Service Monitor Consumer"objConsumer.Message = "A service has changed state."objConsumer.SMTPServer = "mailserver.fabrikam.com"objConsumer.Subject = "Service state change"objConsumer.ToLine = "administrator@fabrikam.com"objConsumer.Put_创建永久事件过滤器更新日期: 2/17/2003 r* o: x% e* \- i1 K1 {, K' j

8 ?3 O* {, b, [# P描述4 p4 A7 z( e) M
创建一个永久事件过滤器来监视服务状态中的改变。
& M K; n( Q; {& } z脚本代码
, H3 q; s$ x3 ^- S# ^6 ]. UstrComputer = "."Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\default")strFilterQuery = "Select * from __InstanceModificationEvent within 3 " & _ "where TargetInstance isa 'Win32_Service'"Set objFilterClass = objWMIService.get("__EventFilter")Set objFilter = objFilterClass.SpawnInstance_objFilter.Name = "Service Monitor Filter"objFilter.QueryLanguage = "wql"objFilter.Query = strFilterQueryobjFilter.Put_枚举 Active Directory 数据库复制伙伴更新日期: 2/17/2003 _4 U) ^0 c# ]

2 D! T" k6 e& a描述
0 x" J- o' {7 z返回域控制器的 Active Directory 复制合作伙伴的列表。需要 Windows .NET Server。
7 A$ l% U& B; j/ q! Y; Z脚本代码
1 p+ ]5 D* ]' V; {) n7 U3 ]% EstrComputer = "."Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & _ strComputer & "\root\MicrosoftActiveDirectory")Set colReplicationOperations = objWMIService.ExecQuery _ ("Select * from MSAD_ReplNeighbor")For each objReplicationJob in colReplicationOperations Wscript.Echo objReplicationJob.Domain Wscript.Echo objReplicationJob.NamingContextDN Wscript.Echo objReplicationJob.SourceDsaDN Wscript.Echo objReplicationJob.LastSyncResult Wscript.Echo objReplicationJob.NumConsecutiveSyncFailuresNext枚举信任合作伙伴的域信息更新日期: 2/17/20032 e% i- c2 b7 ]5 P$ N: E i! X8 t
7 I; _) l0 `9 r" A: }' m; W
描述
) x6 p$ `) N5 M返回本地域信息。需要 Windows Server 2003。
! ^2 B+ U' Y( m, o5 C% K# B6 l脚本代码
; @# l* ?) ~; M8 H' [strComputer = "."Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & _ strComputer & "\root\MicrosoftACtiveDirectory")Set colDomainInfo = objWMIService.ExecQuery _ ("Select * from Microsoft_LocalDOmainInfo")For each objDomain in colDomainInfo Wscript.Echo objDomain.DNSName Wscript.Echo objDomain.FlatName Wscript.Echo objDomain.SID Wscript.Echo objDomain.TreeName Wscript.Echo objDomain.DCNameNext枚举信任关系更新日期: 2/17/2003
, n+ l0 V1 V% p0 c6 B$ h) L! Y6 d% u$ m
描述
3 n5 c; N% W, i9 C( f枚举信任关系。需要 Windows Server 2003。
7 l2 Y3 X+ u3 ?脚本代码: c: {7 K. |) O- U+ h% I
strComputer = "."Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & _ strComputer & "\root\MicrosoftActiveDirectory")Set colTrustList = objWMIService.ExecQuery _ ("Select * from Microsoft_DomainTrustStatus")For each objTrust in colTrustList Wscript.Echo objTrust.TrustedDomain Wscript.Echo objTrust.TrustDirection Wscript.Echo objTrust.TrustType Wscript.Echo objTrust.TrustAttributes Wscript.Echo objTrust.TrustedDCName Wscript.Echo objTrust.TrustStatus Wscript.Echo objTrust.TrustIsOKNext安装 Active Directory 数据库性能计数器更新日期: 2/17/20034 q% S4 `4 p/ l, i r
. W3 X6 I9 l' g$ F
描述/ v. I# m5 o. ^2 P
在域控制器上安装 Active Directory 数据库性能计数器。
9 U% A7 V( d C# p: {0 n @) D脚本代码
$ b( h" }; c* c2 p1 pSet WshShell = WScript.CreateObject("WScript.Shell")Set objFSO = CreateObject("Scripting.FileSystemObject")Set objShell = CreateObject("Shell.Application")objFSO.CreateFolder ("C:\Performance")Set objCopyFile = objFSO.GetFile("C:\windows\system32\esentprf.dll ")objCopyFile.Copy ("C:\performance\esentprf.dll ") WshShell.RegWrite _ "HKLM\System\CurrentControlSet\Services\Esent\Performance\Open", _ "OpenPerformanceData", "REG_SZ"WshShell.RegWrite _ "HKLM\System\CurrentControlSet\Services\Esent\Performance\Collect", _ "CollectPerformanceData", "REG_SZ"WshShell.RegWrite _ "HKLM\System\CurrentControlSet\Services\Esent\Performance\Close", _ "ClosePerformanceData", "REG_SZ"WshShell.RegWrite _ "HKLM\System\CurrentControlSet\Services\Esent\Performance\Library", _ "C:\Performance\Esentprf.dll", "REG_SZ"strCommandText = "%comspec% /c lodctr.exe c:\windows\system32\esentprf.ini" WshShell.Run strCommandText3 M0 U- ~3 r L$ E# K% E( j
监视 Active Directory 复制更新日期: 2/17/2003
! x) G8 ^: {4 m1 `$ [6 m" q, \! m* L: p% ^! L# V2 l' t: t
描述
4 c B0 a8 ~" ^' D返回域控制器上待处理的复制工作的列表。需要 Windows Server 2003。' \: R7 a1 Z( d
脚本代码0 v' }5 r' C5 N& ^
strComputer = "."Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & _ strComputer & "\root\MicrosoftActiveDirectory")Set colReplicationOperations = objWMIService.ExecQuery _ ("Select * from MSAD_ReplPendingOp")If colReplicationOperations.Count = 0 Then Wscript.Echo "There are no replication jobs pending." Wscript.QuitElse For each objReplicationJob in colReplicationOperations Wscript.Echo objReplicationJob.SerialNumber Wscript.Echo objReplicationJob.TimeEnqueued Wscript.Echo objReplicationJob.DsaDN Wscript.Echo objReplicationJob.DsaAddress Wscript.Echo objReplicationJob.NamingContextDn NextEnd If监视可用磁盘空间更新日期: 2/17/2003: L( x9 x- e( F( H. M% Q* E5 N
- {' T: `. \# r0 \6 m
描述$ ~ T7 `+ G/ U- k
如果计算机上任何硬盘的磁盘空间降到 100 MB 以下就发出警报。5 Z+ l4 d3 ~/ P; O8 l
脚本代码+ O' W: l& W, c w4 e
Const LOCAL_HARD_DISK = 3strComputer = "."Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colMonitoredDisks = objWMIService.ExecNotificationQuery _ ("Select * from __instancemodificationevent within 30 where " _ & "TargetInstance isa 'Win32_LogicalDisk'")i = 0Do While i = 0 Set objDiskChange = colMonitoredDisks.NextEvent If objDiskChange.TargetInstance.DriveType = LOCAL_HARD_DISK Then If objDiskChange.TargetInstance.Size < 100000000 Then Wscript.Echo "Hard disk space is below 100000000 bytes." End If End IfLoop监视可用内存数量更新日期: 2/17/2003
L/ P& h* Y: U5 C9 Y( A) z
; L' k/ D! X' I9 F2 `1 H' t' E描述
% z( g9 t; H1 Z8 L如果计算机上的可用内存数量降到 4 MB 以下就发出警报。需要 Windows XP 或 Windows Server 2003。4 {4 z. @: P$ F' {1 Z# b
脚本代码
1 T. \( _0 N V1 G. [strComputer = "."Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")set objRefresher = CreateObject("WbemScripting.SWbemRefresher")Set objMemory = objRefresher.AddEnum _ (objWMIService, "Win32_PerfFormattedData_PerfOS_Memory").objectSetobjRefresher.RefreshDo For each intAvailableBytes in objMemory If intAvailableBytes.AvailableMBytes < 4 Then Wscript.Echo "Available memory has fallen below 4 megabytes." End If Next objRefresher.RefreshLoop监视计算机电源状态的改变更新日期: 2/17/2003
6 C- A u& y- f/ M8 I( R( B& [$ H7 o! ]: p5 v& R0 k' D
描述
3 F" ^* v; }1 Z9 T% _如果计算机的电源状态发生改变(例如进入或离开挂起模式)就发出警报。
' O+ w3 Z3 o! ]脚本代码
+ Y5 F, i7 y/ ^; H! G7 Q$ ASet colMonitoredEvents = GetObject("winmgmts:")._ ExecNotificationQuery("Select * from Win32_PowerManagementEvent")Do Set strLatestEvent = colMonitoredEvents.NextEvent Wscript.Echo strLatestEvent.EventTypeLoop监视服务状态的改变更新日期: 2/17/20039 I/ ~7 E' k+ F: N- G5 w: p
" W* G6 ^4 z9 ~7 {
描述: \1 h0 `. c6 S0 x* s: {- m
在任何时候只要服务状态发生改变(例如,活动服务暂停或停止),临时时间消费程序就发出警报。
4 D( m' E" e. P8 g- ?2 T& v脚本代码
$ H4 e$ v$ S% A- t W4 |strComputer = "."Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colServices = objWMIService. _ ExecNotificationQuery("Select * from __instancemodificationevent " _ & "within 30 where TargetInstance isa 'Win32_Service'")i = 0Do While i = 0 Set objService = colServices.NextEvent If objService.TargetInstance.State <> _ objService.PreviousInstance.State Then Wscript.Echo objService.TargetInstance.Name _ & " is " & objService.TargetInstance.State _ & ". The service previously was " & objService.PreviousInstance.State & "." End IfLoop监视计算机的可用性更新日期: 2/17/2003
: h: s8 `, Z/ X. @6 ?% {5 k) M8 ?9 p' I" m
描述) W3 j* j/ \' o. p1 m2 e
使用 Win32_PingStatus 类别验证是否可以通过网络访问计算机。需要 Windows XP 或 Windows .NET Server。4 p- W& ^9 N: { M8 D( c
脚本代码
* `! R/ s: s9 |2 o$ cstrComputer = "."Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colPingedComputers = objWMIService.ExecQuery _ ("Select * from Win32_PingStatus Where Address = '192.168.1.37'")For each objComputer in colPingedComputers If objComputer.StatusCode = 0 Then Wscript.Echo "Remote computer responded." Else Wscript.Echo "Remote computer did not respond." End IfNext监视计算机健康状况更新日期: 2/17/2003
5 o5 _% ^/ O/ F+ U; W S- _9 Y3 t; Y
描述
& Q x& F) g0 G8 `使用加热的性能计数器和 SWbemRefresher 对象监视计算机上的三个性能计数器。如果三个计数器中的任何一个超过指定的域值就发出警报。需要 Windows XP 或 Windows Server 2003。) F# }/ @) D$ R4 w. S, s
脚本代码, q( o4 W3 Z- k" p
strComputer = "."Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")set objRefresher = CreateObject("WbemScripting.Swbemrefresher")Set objMemory = objRefresher.AddEnum _ (objWMIService, "Win32_PerfFormattedData_PerfOS_Memory").objectSetSet objDiskQueue = objRefresher.AddEnum _ (objWMIService, "Win32_PerfFormattedData_PerfDisk_LogicalDisk"). _ objectSetSet objQueueLength = objRefresher.AddEnum _ (objWMIService, "Win32_PerfFormattedData_PerfNet_ServerWorkQueues"). _ objectSetobjRefresher.RefreshintHealthStatus = 0Do For each intAvailableBytes in objMemory If intAvailableBytes.AvailableMBytes < 4 Then intHealthStatus = intHealthStatus + 1 End If Next For each intQueueLength in objDiskQueue If intQueueLength.CurrentDiskQueueLength > 2 Then intHealthStatus = intHealthStatus + 1 End If Next For each intServerQueueLength in objQueueLength If intServerQueueLength.QueueLength > 4 Then intHealthStatus = intHealthStatus + 1 End If Next If intHealthStatus > 0 Then Wscript.Echo "Unhealthy." Else Wscript.Echo "Healthy." End If intHealthStatus = 0 Wscript.Sleep 10000 objRefresher.RefreshLoop监视计算机的正常运行时间更新日期: 2/17/20032 q* {) m) u# A- {% l
6 q l. U+ t; z+ g
描述
2 S% M2 p' ^. E计算计算机从上一次启动以来的天数。需要 Windows XP 或 Windows .NET Server。# ?6 A* h" }9 A: z
脚本代码
B4 h& G& H( QSet dtmConvertedDate = CreateObject("WbemScripting.SWbemDateTime")strComputer = "."Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colOperatingSystems = objWMIService.ExecQuery _ ("Select * from Win32_OperatingSystem")For Each objOS in colOperatingSystems dtmConvertedDate.Value = objOS.LastBootUpTime dtmLastBootUpTime = dtmConvertedDate.GetVarDate dtmSystemUptime = DateDiff("d", dtmLastBootUpTime, Now) Wscript.Echo dtmSystemUptime Next监视每秒的磁盘字节数更新日期: 2/17/20036 [( \1 J# A2 v! e" {: n

! |+ w1 j; c* c' b: \# x9 U描述# r2 \( o# T. i7 p# e& d$ F5 Z' I
使用加热的性能计数器监视计算机上每秒的磁盘字节数。需要 Windows XP 或 Windows Server 2003。. c; }& I* z$ S6 P. n. ?
脚本代码
- `+ u! j, D0 |0 E L2 F" EstrComputer = "."Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")set objRefresher = CreateObject("WbemScripting.SWbemRefresher")Set colDiskDrives = objRefresher.AddEnum _ (objWMIService, "Win32_PerfFormattedData_PerfDisk_LogicalDisk").objectSetobjRefresher.RefreshFor i = 1 to 500 For Each objDiskDrive in colDiskDrives Wscript.Echo "Drive name: " & objDiskDrive.Name Wscript.Echo "Disk bytes per second: " & objDiskDrive.DiskBytesPerSec Wscript.Sleep 2000 objRefresher.Refresh NextNext监视磁盘驱动器的剩余空间更新日期: 2/17/2003' ]5 a) {) {& |8 u

: `: t0 ~. ~! c- c; f) H, [描述
0 [: z1 g0 E# c! F6 s* \使用加热的性能计数器检索计算机上的剩余磁盘空间。需要 Windows XP 或 Windows .NET Server。
1 y9 T% v5 y0 m7 X脚本代码1 D- |2 g- l. Z3 ]
strComputer = "."Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colDiskDrives = objWMIService.ExecQuery _ ("Select * from win32_perfformatteddata_perfdisk_logicaldisk where Name <> '_Total'")For each objDiskDrive in colDiskDrives Wscript.Echo "Drive Name: " & objDiskDrive.Name Wscript.Echo "Free Space: " & objDiskDrive.FreeMegabytesNext监视域控制器的性能更新日期: 2/17/2003! r% X+ n- m4 `1 ?

) E# U# n$ l) g描述
' W' g9 }' f* r7 j脚本代码
6 g6 D% X2 d" L6 M# e. s: ^2 DstrComputer = "."Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colDatabases = objWMIService.ExecQuery _ ("Select * from Win32_PerfFormattedData_NTDS_NTDS")For Each objADDatabase in colDatabases Wscript.Echo objADDatabase.DSThreadsInUse Wscript.Echo objADDatabase.LDAPBindTime Wscript.Echo objADDatabase.LDAPClientSessionsNext监视事件日志更新日期: 2/17/2003 ]$ \* K# z2 r$ u/ P7 n+ U

7 d) g! @5 i) ?) {+ `; R描述
9 J: ^/ ?: d* T创建临时事件消费程序来监视事件 ID 为 533 的事件日志。3 R& v7 a* T. h
脚本代码
# ]% a* `3 `4 mstrComputer = "."Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel= impersonate, (Security)}!\\" & strComputer & "\root\cimv2")Set colMonitoredEvents = objWMIService.ExecNotificationQuery _ ("Select * from __instancecreationevent where TargetInstance isa 'Win32_NTLogEvent' and TargetInstance.EventCode = '533' ")Do Set objLatestEvent = colMonitoredEvents.NextEvent strAlertToSend = objLatestEvent.TargetInstance.User _ & " attempted to access DatabaseServer." Wscript.Echo strAlertToSendLoop监视 FRS 复制更新日期: 2/17/2003
9 f$ ^: `# o4 L$ Q
' k& v+ x }8 O6 V描述
7 a" G* y& A- {: O1 T# l使用加热的性能计数器监视域控制器上的文件复制服务性能。需要 Windows .NET Server。
) _$ m- @2 `! G" }5 @脚本代码
( O$ l3 i: H: C/ i$ jstrComputer = "."Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colFRSSet = objWMIService.ExecQuery _ ("Select * from Win32_PerfFormattedData_FileReplicaConn_FileReplicaConn")For Each objFRSInstance in colFRSSet Wscript.Echo objFRSInstance.RemoteChangeOrdersReceived Wscript.Echo objFRSInstance.RemoteChangeOrdersSent Wscript.Echo objFRSInstance.PacketsSentNext监视进程的可用性更新日期: 2/17/2003
/ k; u5 [. I# s/ K( k$ ]2 O5 I7 A2 Z1 |: O2 b0 K( h
描述
8 @" c0 |$ o& l& j识别假定的进程数据库是否正在运行。+ t, b6 }, |5 a) G: U: J
脚本代码
5 r" |2 l0 u! e3 F; U: }; Y' LstrComputer = "."Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colProcesses = objWMIService.ExecQuery _ ("Select * from Win32_Process Where Name = 'Database.exe'")If colProcesses.Count = 0 Then Wscript.Echo "Database.exe is not running."Else Wscript.Echo "Database.exe is running."End If监视进程的创建更新日期: 2/17/2003
. [# l! l2 P; E4 A0 A& Z' R
+ P5 ~) G: C" M描述
1 z% e$ H& [1 R) d; @9 U在每次创建新的进程时,临时事件消费程序都发出警报。
/ I% ` C5 M- l9 ?) m* z) V- ~9 {脚本代码
& x' r* J6 m: w; c+ zstrComputer = "."Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colMonitoredProcesses = objWMIService. _ ExecNotificationQuery("select * from __instancecreationevent " _ & " within 1 where TargetInstance isa 'Win32_Process'")i = 0Do While i = 0 Set objLatestProcess = colMonitoredProcesses.NextEvent Wscript.Echo objLatestProcess.TargetInstance.NameLoop监视进程的删除更新日期: 2/17/2003- x% ]. @/ C ]0 e

( V1 o" y9 B8 ~; j/ w描述% e9 x2 _* {2 V8 i( P- M
在每次进程终止时,临时事件消费程序都发出警报。
; u. w6 H& t2 e5 d/ J1 A% H脚本代码2 |0 B# e4 A$ ~7 W* p* Y) k
strComputer = "."Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colMonitoredProcesses = objWMIService. _ ExecNotificationQuery("select * from __instancedeletionevent " _ & "within 1 where TargetInstance isa 'Win32_Process'")i = 0Do While i = 0 Set objLatestProcess = colMonitoredProcesses.NextEvent Wscript.Echo objLatestProcess.TargetInstance.NameLoop监视处理器的使用情况更新日期: 2/17/2003" R5 n2 C4 [. G' q1 u
, L$ \+ G" a0 Y; U+ ^' _
描述) l* p* r9 J) x* x
使用加热的性能计数器监视计算机处理器的使用情况。如果处理器的使用率在 10 次连续测量(测量时间间隔为 6 秒)中均超过 90% 就发出警报。* A. x$ e [7 b4 Y3 P' P
脚本代码& E! T/ k+ V3 |- m7 u2 }; m
strComputer = "."Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")set objRefresher = CreateObject("WbemScripting.Swbemrefresher")Set objProcessor = objRefresher.AddEnum _ (objWMIService, "Win32_PerfFormattedData_PerfOS_Processor").objectSetintThresholdViolations = 0objRefresher.RefreshDo For each intProcessorUse in objProcessor If intProcessorUse.PercentProcessorTime > 90 Then intThresholdViolations = intThresholdViolations + 1 If intThresholdViolations = 10 Then intThresholdViolations = 0 Wscript.Echo "Processor usage threshold exceeded." End If Else intThresholdViolations = 0 End If Next Wscript.Sleep 6000 objRefresher.RefreshLoop监视进程使用处理器的情况更新日期: 2/17/2003
# S* ^( S+ Z. [ N5 z( V1 ?/ i6 y U1 ~" ^$ C- z
描述
2 M5 @* V$ t( y0 O- R报告运行在计算机上的每个进程使用处理器的时间(以秒为单位)。6 N0 i' Z7 e. y6 F9 L- B- t
脚本代码' X2 K' P5 O/ b. Y
strComputer = "."Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colProcesses = objWMIService.ExecQuery _ ("Select * from Win32_process")For Each objProcess in colProcesses sngProcessTime = ( CSng(objProcess.KernelModeTime) + _ CSng(objProcess.UserModeTime)) / 10000000 Wscript.echo objProcess.name & VbTab & sngProcessTimeNext监视进程的性能更新日期: 2/17/2003
3 H' u1 y# l* H9 t6 a4 p9 L- R! I7 [5 k+ l
描述
# c i4 I, g& h. B% V报告运行在计算机上的所有进程的统计信息(例如线程计数和工作集大小)。
: c) [( r; c* q' P9 s# b1 a6 q脚本代码
! H+ I7 J& h0 m% w |strComputer = "."Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colProcessList = objWMIService.ExecQuery _ ("Select * from Win32_Process")For Each objProcess in colProcessList Wscript.Echo "Process: " & objProcess.Name Wscript.Echo "Process ID: " & objProcess.ProcessID Wscript.Echo "Thread Count: " & objProcess.ThreadCount Wscript.Echo "Page File Size: " & objProcess.PageFileUsage Wscript.Echo "Page Faults: " & objProcess.PageFaults Wscript.Echo "Working Set Size: " & objProcess.WorkingSetSize Next确定系统的正常运行时间更新日期: 2/17/2003
( Q' _1 e7 x, t# ^- g
$ o, P3 G, ]; b9 Y- b2 @描述" f' D1 ^1 C2 M" T7 b- v* w
计算系统的正常运行时间;即计算机从上一次启动以来运行的小时数。
+ g+ {" i& L- V+ |+ `" z1 A有关在这段代码中使用的 Win32_OperatingSystem 类别的更多信息,请单击此处
6 z2 X+ s: ^$ i4 }) P/ ]支持平台$ n& v6 B/ M% ^7 {; w
Windows XP4 d* U6 w& k8 X# q+ S

1 \% v8 ^, z; n, d
Windows Server 20038 y4 H% z3 W+ J+ ~
8 D/ K! ]' T; W* ?5 V5 _
Windows 2000 @* u- S, U1 r8 M0 {9 ^
! t6 S! R- V; z7 y
Windows NT 4.0, _2 \1 O. u0 {2 c% r4 K
Yes, with WMI installed, z+ u q7 B, i: O& u" V
Windows 98( w/ B0 e0 E* K& |3 V9 K' x4 S& i1 b% c
Yes, with WMI installed
) s. P, A- Z) M2 C) M$ S. w5 |

* v: L" ^& [$ s; K: f u脚本代码
( I% M$ x$ s9 i. R1 ?strComputer = "."Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colOperatingSystems = objWMIService.ExecQuery _ ("Select * from Win32_OperatingSystem")For Each objOS in colOperatingSystems dtmBootup = objOS.LastBootUpTime dtmLastBootupTime = WMIDateStringToDate(dtmBootup) dtmSystemUptime = DateDiff("h", dtmLastBootUpTime, Now) Wscript.Echo dtmSystemUptimeNextFunction WMIDateStringToDate(dtmBootup) WMIDateStringToDate = CDate(Mid(dtmBootup, 5, 2) & "/" & _ Mid(dtmBootup, 7, 2) & "/" & Left(dtmBootup, 4) _ & " " & Mid (dtmBootup, 9, 2) & ":" & _ Mid(dtmBootup, 11, 2) & ":" & Mid(dtmBootup, _ 13, 2))End Function

TOP