📄 JScript (WSH)

Get Processes Report (JScript)

Queries Win32_Process via WMI and prints Processes to the console — JScript, VBScript's WSH sibling language.

By WindowsScripting.com · 1 KB
GetProcessReport.js
// ============================================================
// GetProcessReport.js
//
// Reports Processes via WMI (Win32_Process). JScript (Windows Script Host) —
// VBScript's sibling language, run the same way via cscript/wscript.
//
// Usage: cscript GetProcessReport.js
// ============================================================

var objWMIService = GetObject("winmgmts:\\\\.\\root\\cimv2");
var colItems = objWMIService.ExecQuery("SELECT Name, ProcessId, WorkingSetSize, ThreadCount FROM Win32_Process");

var e = new Enumerator(colItems);
var output = "";
var count = 0;

for (; !e.atEnd(); e.moveNext()) {
    var item = e.item();
    output += "Name: " + item.Name + "\n";
    output += "ProcessId: " + item.ProcessId + "\n";
    output += "WorkingSetSize: " + item.WorkingSetSize + "\n";
    output += "ThreadCount: " + item.ThreadCount + "\n";
    output += new Array(41).join("-") + "\n";
    count++;
}

if (count === 0) {
    WScript.Echo("No Processes found.");
} else {
    WScript.Echo(output);
}