/**//* * cscript ListDrive.js */ var oFSO = new ActiveXObject("Scripting.FileSystemObject"); var enDrives = new Enumerator(oFSO.Drives); var oDrive; while (! enDrives.atEnd()) { oDrive = enDrives.item();
if (oDrive.IsReady) { WScript.Echo(oDrive.DriveLetter + ":"); }
enDrives.moveNext(); } 例2:通过wmi枚举所有的进程
/**//* * cscript ListProcess.js */ var sComputerName = "."; var oLoc = new ActiveXObject("WbemScripting.SWbemLocator"); var oSvc = oLoc.ConnectServer(sComputerName, "root\\cimv2"); var colItems = oSvc.ExecQuery("SELECT * FROM Win32_Process"); var enProcesses = new Enumerator(colItems);
while (! enProcesses.atEnd()) { WScript.Echo(enProcesses.item().Name); enProcesses.moveNext(); }