通过调用WMI对象,可以在VBS脚本中方便的管理系统进程。
搜索进程
通过进程名称查询进程个数:
strComputer = "."
strProcess = "'PSPad.exe'"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = " & strProcess )
WScript.Echo colProcess.count
杀死进程
先通过进程名字得到列表,然后通过循环杀掉该名称的所有进程。
strComputer = "."
strProcessKill = "'otrun.exe'"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = " & strProcessKill )
For Each objProcess in colProcess
objProcess.Terminate()
Next
WSCript.Echo "Just killed process " & strProcessKill _
& " on " & strComputer
WScript.Quit
' End of WMI Example of a Kill Process
打印管理
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPrintQueues = objWMIService.ExecQuery _
("Select * from Win32_PerfFormattedData_Spooler_PrintQueue Where Name <> '_Total'")
For Each objPrintQueue in colPrintQueues
If objPrintQueue.Jobs > 10 Then
sbj = "WPh - Large number of documents in Printer Queue"
tbody = "Current " & objPrintQueue.Jobs & " jobs on printer: " & objPrintQueue.Name
Call SendMail(mfrom,rcpt,sbj,tbody,attachfile,serverIP)
End If
Next
Comments
There are currently no comments
New Comment