#! perl -slw use strict; use Win32::Process; my %priorityClasses = ( realtime => REALTIME_PRIORITY_CLASS, high => HIGH_PRIORITY_CLASS, above => 0x00008000, ## ABOVE_NORMAL_PRIORITY_CLASS (Not NT/95/96/ME). normal => NORMAL_PRIORITY_CLASS, below => 0x00004000, ## BELOW_NORMAL_PRIORITY_CLASS (Not NT/95/96/ME). idle => IDLE_PRIORITY_CLASS, ); my %priority2class = reverse %priorityClasses; my( $pid, $priorityClass ) = @ARGV; $priorityClass = lc $priorityClass; die 'Priority class must be specified as [realtime|above|normal|below|idle]' unless exists $priorityClasses{ $priorityClass }; my( $OS, $major, $minor, $build, $id ) = Win32::GetOSVersion(); die "Priority class $priorityClass not available on $OS" if $priorityClass eq 'above' or $priorityClass eq 'below' and $major < 5; my( $hProcess, $class ); Win32::Process::Open( $hProcess, $pid, 0 ) or die $^E; $hProcess->GetPriorityClass( $class ); print "Process $pid had priority class: ", $priority2class{ $class }; $hProcess->SetPriorityClass( $priorityClasses{ $priorityClass } ) or die $^E; $hProcess->GetPriorityClass( $class ); print "Process $pid now has priority class: ", $priority2class{ $class }; __END__ P:\test>SetPriority.pl 1892 high Process 1892 had priority class: normal Process 1892 now has priority class: high P:\test>SetPriority.pl 1892 normal Process 1892 had priority class: high Process 1892 now has priority class: normal