Monday, December 8, 2008

Changing the Priority Of a Running Process

Changes the priority of a running instance of Notepad.exe from Normal to Above Normal.

Const ABOVE_NORMAL = 32768
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery _
    ("Select * from Win32_Process Where Name = 'Notepad.exe'")
For Each objProcess in colProcesses
    objProcess.SetPriority(ABOVE_NORMAL) 
Next

This is a VB Script, this can be used by saving the file in .vbs file