Last active
May 3, 2017 09:11
-
-
Save MarkTiedemann/26f153dfd3f6a318bdd3c395a60650fa to your computer and use it in GitHub Desktop.
CPU percentage of a process
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' cscript.exe //B //NoLogo pid-cpu.vbs | |
set fs = createObject("Scripting.FileSystemObject") | |
set stdout = fs.getStandardStream(1) | |
' https://msdn.microsoft.com/en-us/library/aa393838(v=vs.85).aspx | |
set refresher = createObject("WbemScripting.SWbemRefresher") | |
set namespace = getObject("winmgmts:root\cimv2") | |
' https://msdn.microsoft.com/en-us/library/aa394323(v=vs.85).aspx | |
set perfdata = refresher.addEnum(namespace, "Win32_PerfFormattedData_PerfProc_Process").objectSet | |
samples = 100 | |
pid = 1234 | |
for i = 1 to samples | |
refresher.refresh() | |
for each data in perfdata | |
if data.idProcess = pid then | |
stdout.writeLine(data.percentProcessorTime) | |
end if | |
next | |
next |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment