Passing In PIDs and Priorities
If you want to use priority.pl to discover a process's current priority class, run the following command on the local system:
perl priority.pl PID
where PID is the process's PID (e.g., 532). To query more than one process, pass in multiple PIDS separated by a space, as in
perl priority.pl 532 1112 8832
To set a new priority for the specified PID, add the -s option and the priority class:
perl priority.pl -s low PID
To set the priority for more than one process, pass in multiple PIDS, separated by a space. For example, the command
perl priority.pl -s low 532 1112 8832
sets the Low priority class for the processes that have PIDs 532, 1112, and 8832. You can specify only one class, which will go into effect for all the specified PIDs.
Rule Your Scripts
While writing this column, I used priority.pl to tame some mischievous processes. I was using Microsoft Windows Media Encoder to encode a video into Microsoft Windows Media Format, and the process was taking up too much CPU time. After I ran priority.pl and passed in the -s low parameter and the offending application's PID, the encoder slid into the background, where it no longer affected my work.
This type of coding is one of the most powerful and useful techniques you can use to manage your machines, especially in any script you write to work as a background task or Win32 service. Setting the right priority class makes a script behave and can prevent a world of frustration for you and other users. You can download the code in Listing 1 and priority.pl (in its entirety) from the Windows Scripting Solutions Web site. Go to http://www.winnetmag.com/windowsscripting, enter InstantDoc ID 42375 in the InstantDoc ID box, then click the 42375.zip hotlink.