我是 vbs 的新手,但已经用 c、c++ n java 进行过编程。我尝试通过互联网搜索,但我仍然找不到我错在哪里。我正在编写一个脚本来杀死一个名为 rundll 的进程,如果它超过 20% 的 cpu 使用率。
Option Explicit
DIM MyPID(5), objProcess, objItems, objitem
DIM XX, I
XX = -1
dim objService
set objService = getobject("winmgmts:")
dim Process
for each Process in objService.InstancesOf("Win32_process")
if Process.Name = "rundll32.exe" Then XX = XX + 1
if Process.Name = "rundll32.exe" Then MyPID(XX) = Process.processid
Next
For I = 0 To 5
Set objProcess = GetObject("winmgmts:{impersonationLevel=impersonate}//localhost")
Set objItems = objProcess.ExecQuery("Select PercentProcessorTime from Win32_PerfFormattedData_PerfProc_Process where IDProcess=" &MyPID(I)& "")
if (IsNull(objItems)) Then
Wscript.Echo "No process found"
Exit For
End if
for each objItem in objItems
if objItems = Null Then
Wscript.Echo "No process found"
elseif objItem>20 Then Wscript.Echo "Criminal process found :" & MyPID(I) & " = " & objItem.PercentProcessorTime
End if
NEXT
NEXT
如果脚本没有找到进程,它应该打印没有找到进程,而不是我现在得到的复杂的空警报
任何帮助将不胜感激,所以建议