CSCRIPT.EXE
and a CommandLine containing that name. Any matches (should be only one, but could be more) are boosted to HIGH process priority. This demonstrates WMI calls from both VBScript and JScript. Note the need to explicitly define an Enumerator in the JScript version.
Option Explicit Dim sName Dim sComputer Dim oWMI Dim cProcesses Dim oProcess Const HIGH = 256 sComputer = "." Set oWMI = GetObject("winmgmts:\\" & sComputer & "\root\cimv2") sName = WScript.ScriptName Set cProcesses = oWMI.ExecQuery("Select * from Win32_Process Where Name = 'cscript.exe' And CommandLine LIKE '%" & sName & "%'") For Each oProcess In cProcesses oProcess.SetPriority(HIGH) WScript.Echo "Boosted myself" NextAnd in JScript
var HIGH = 256; var sComputer = "."; var sName = WScript.ScriptName; var query = GetObject("winmgmts:\\\\" + sComputer + "\\root\\cimv2") .ExecQuery("Select * from Win32_Process " + "Where Name = 'cscript.exe' And CommandLine LIKE '%" + sName + "%'") // Enumerate WMI objects var cProcesses = new Enumerator(query); for ( ; !cProcesses.atEnd(); cProcesses.moveNext()) { var oProcess = cProcesses.item() oProcess.Priority = HIGH WScript.Echo( "Boosted myself") }© Copyright Bruce M. Axtens, 2014
No comments:
Post a Comment