这是一个HTML应用程序,允许您使用vbscript监视本地计算机或远程计算机上任何一项任务的CPU使用率(在任务管理器中看到)。 然后,当该进程处于空闲状态时,它将向您发出警报。 我今天早上把它们放在一起是因为我厌倦了在远程计算机上启动程序,并不断地重新连接以查看工作是否完成。 可以很容易地将此代码修改为远程计算机的完整“任务管理器”。实际上,我想我可以这样做。 我会的,我将为此做一个分步的文章。 因为我很无聊。
(您需要远程计算机的用户名和密码)
(将此代码复制到空白文本文档中,并以扩展名“ .hta”保存)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Teh Waiter</title>
<HTA:APPLICATION id="prjIS" MINIMIZEBUTTON="yes" MAXIMIZEBUTTON="no" INNERBORDER="yes" BORDER="thin" SINGLEINSTANCE="yes" APPLICATIONNAME="Waiting Script">
<SCRIPT language="VBScript">
<!--
Sub Window_onLoad
Dim objWMISer, objItem
Dim colItems
Dim intLeft, intTop
Set objWMISer = GetObject("winmgmts:\\.\root\cimv2")
Set colItems = objWMISer.ExecQuery("Select * From Win32_DesktopMonitor")
'Set Window Size
For Each objItem in colItems
intWidth = objItem.ScreenWidth
intHeight = objItem.ScreenHeight
Exit For
Next
intLeft = (intWidth - 385) / 2
intTop = (intHeight - 230) / 2
window.resizeTo 385,230
window.MoveTo intLeft, intTop
End Sub
Function IsValidIp(sIpAddress)'Well..is it?
Dim aTmp
IsValidIp = False
aTmp = split(sIpAddress,".")
If UBound(aTmp) <> 3 Then Exit Function
For Each field In aTmp
If field > 255 Then Exit Function
Next
IsValidIp = True
End Function
'This was complicated..
'Sets cursor to end of text when focus is gained
Sub txtIP_OnFocus
Set it = document.Selection.CreateRange()
it.moveStart "Character", 15
it.select
End Sub
Dim sObjectPath, strIPAddress, strUser, strPass, strName
Dim blnIdle, blnIsDone, blnFocus
Dim intWait, intTime
Dim wmi_service, perf_instance1
Dim N1, N2, D1, D2
Dim TimerID, TimerWork
Sub btnDoIt_OnClick
document.getElementById("btnDoIt").disabled = "disabled"
strIPAddress = document.getElementById("txtIP").value
strUser = "remoteuser"
strPass = "secretpassword"
strName = document.getElementById("txtName").value
intTime = CInt(document.getElementById("txtTime").value)
blnIsDone = false
blnIdle = false
intWait = 0
If trim(strName) = "" Then
msgbox "Enter a process to wait for!"
document.getElementById("btnDoIt").disabled = ""
Exit Sub
End If
sObjectPath = "Win32_PerfRawData_PerfProc_Process.Name=" & chr(34) & strName & chr(34)
If strIPAddress = "." Then
Set wmi_service = GetObject("winmgmts:{impersonationlevel=impersonate}!\\.\root\cimv2")
Else
If IsValidIp(strIPAddress) Then
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set wmi_service = objSWbemLocator.ConnectServer(strIPAddress, "root\cimv2", strUser, strPass)
Else
msgbox "Invalid Ip Address"
document.getElementById("btnDoIt").disabled = ""
Exit Sub
End If
End If
Set perf_instance1 = wmi_service.get( sObjectPath )
N1 = perf_instance1.PercentProcessorTime
D1 = perf_instance1.TimeStamp_Sys100NS
TimerID = window.setInterval("TehLoop", 1000)
TimerWork = window.setInterval("StillWorking", 400)
If strIPAddress <> "." Then
document.getElementById("divTitle").innerText = "Waiting for " & strName & " on " & strIPAddress
Else
document.getElementById("divTitle").innerText = "Waiting for " & strName
End If
document.getElementById("divMain").style.display = "none"
document.getElementById("divStatus").style.display = ""
document.title = "Waiting.."
End Sub
Sub TehLoop
Dim perf_instance2
Set perf_instance2 = wmi_service.get( sObjectPath )
N2 = perf_instance2.PercentProcessorTime
D2 = perf_instance2.TimeStamp_Sys100NS
'Found This formula somewhere on the interwebs
' CounterType - PERF_100NSEC_TIMER
' Formula = ((N2 - N1) / (D2 - D1)) x 100
If ( 0 = (D2-D1) ) Then
msgbox "process " & strName & " was not found"
blnIsDone = true
Else
PercentProcessorTime = ((N2 - N1) / (D2 - D1)) * 100
document.getElementById("divUsage").innerText = "Usage: " & PercentProcessorTime
If PercentProcessorTime = 0 Then
intWait = intWait + 1
Progress
If intWait >= intTime Then
blnIsDone = true
blnIdle = true
End If
Else
Progress
intWait = 0
End If
End If
N1 = N2
D1 = D2
If blnIsDone Then
btnCancel_OnClick
End If
End Sub
Sub Progress
document.getElementById("divIdle").innerText = "Idle Seconds: " & intWait & " of " & intTime
If blnFocus Then
document.title = "Waiting.."
Else
document.title = strName & " - " & intWait & " of " & intTime & " seconds"
End If
End Sub
Sub StillWorking
Set div = document.getElementById("divWait")
If div.innerText <> "Waiting...." Then
div.innerText = div.innerText & "."
Else
div.innerText = "Waiting."
End If
End Sub
Sub btnCancel_OnClick
Set wmi_service = nothing
If blnIdle Then
document.title = strName & " is idle"
Set objWC = window.document.getElementById("sndWC")
If Not objWC Is Nothing Then
objWC.src = "WorkCom.wav"
End If
msgbox strName & " is idle"
End If
window.clearInterval(TimerID)
window.clearInterval(TimerWork)
document.getElementById("btnDoIt").disabled = ""
document.getElementById("divMain").style.display = ""
document.getElementById("divStatus").style.display = "none"
document.title = "Teh Waiter"
End Sub
Sub FocusOut
blnFocus = False
End Sub
Sub FocusIn
blnFocus = True
End Sub
-->
</SCRIPT>
</head>
<body onfocusin="FocusIn" onfocusout="FocusOut" bgcolor="black">
<form id="frmExecute">
<center><font face="Comic Sans MS" color="blue">
<bgsound src="" id="sndWC" />
<div id="divMain">
IP Address ("." for local):
<br>
<INPUT id="txtIP" tabIndex="1" type="text" maxLength="15" size="13" value="." name="txtIP" />
<br>
Process name (exp. "explorer"):
<br>
<INPUT id="txtName" tabIndex="2" type="text" size="13" value="explorer" name="txtName" />
<br>
Idle Time in seconds:
<br>
<INPUT id="txtTime" tabIndex="3" type="text" size="13" value="4" name="txtTime" />
<br>
<INPUT id="btnDoIt" tabIndex="4" type="button" value="Start" name="btnDoIt" />
<br>
</div>
<div id="divStatus" style="display: none">
<INPUT id="btnCancel" tabIndex="4" type="button" value="Stop" name="btnCancel" />
<br><br>
<div id="divTitle"></div>
<div id="divUsage">Usage: </div>
<div id="divIdle">Idle Seconds: </div>
<div id="divWait" style="color: red">Waiting...</div>
</div>
</font></center>
</form>
</body>
</html>
From: https://bytes.com/topic/windows/insights/755119-hta-cpu-usage-monitor