HANDLE hProcessSnap = NULL;
BOOL bRet = FALSE;
THREADENTRY32 te32 = {0};
// Take a snapshot of all processes in the system.
hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
if (hProcessSnap == INVALID_HANDLE_VALUE)
return (FALSE);
// Fill in the size of the structure before using it.
te32.dwSize = sizeof(THREADENTRY32);
// Get first process information
Thread32First(hProcessSnap, &te32)
// get the thread priority
HANDLE hThread;
hThread = OpenThread(THREAD_SET_INFORMATION|THREAD_QUERY_INFORMATION, FALSE, te32.th32ThreadID);
// set new priority class
if (SetThreadPriority(hThread, threadPriority) != TRUE)
{
cerr << "SetThreadPriority() ";
printError();
}
CloseHandle(hThread);
####
$pid = 952;
# 952 is a running job pid
use threads;
use threads::shared;
use Win32::API;
Win32::API->Import( 'Kernel32', q[ DWORD GetLastError( ) ] );
Win32::API->Import( 'Kernel32',
q[ HANDLE CreateToolhelp32Snapshot( DWORD dwFlags, DWORD th32ProcessID ) ] );
$hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, $pid);
print "hProcessSnap = $hProcessSnap \n";
####
Win32::API->Import( 'Kernel32',
q[ BOOL Thread32First( HANDLE hSnapshot, THREADENTRY32 lpte)] );
$retcode = GetLastError();
print "import threadfirst error was $retcode \n";
####
# typedef for THREADENTRY32
typedef Win32::API::Struct AA => qw{
DWORD dwSize;
DWORD cntUsage;
DWORD th32ThreadID;
DWORD th32OwnerProcessID;
LONG tpBasePri;
LONG tpDeltaPri;
DWORD dwFlags;
};
my $Point = Win32::API::Struct->new( AA );
$Point->{dwSize} = 24;
##$size=Win32::API::Struct->sizeof(AA);
##always returns 0. ??
Thread32First($hProcessSnap, LPAA);
$retcode = GetLastError();
print "threadfirst error was $retcode \n";
####
Win32::API->Import( 'Kernel32', q[HANDLE OpenThread( DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwThreadId) ] );
$hThread = OpenThread(THREAD_SET_INFORMATION|THREAD_QUERY_INFORMATION,
FALSE, $point->{th32ThreadID});
Win32::API->Import( 'Kernel32', q[ BOOL SetThreadPriority( HANDLE hThread, int nPriority ) ] );
SetThreadPriority( hThread, $threadpriority );