I wish to have a script or small command to be able to set and save priority of a self starting Windows process.
Every time Windows starts this process I would like it to be run in real time priority without having to rerun the script or command.
For example, the program prime 95 is an exe that will generate worker threads on its own then when they are completed they will end and then begin the next round of worker threads thus negating any manual set priorities when the threads are regenerated.
I would like the ability to lock these threads to real time priority at all times. Programs such as process lasso etc do not work for self generated process like this.
Best How To :
You will have to do a bit of coding to achieve this!
It requires a simple DLL and a simple EXE file. The EXE will start your application "prime 95.exe" and will inject the DLL to it. Inside the DLL, you will get a notification each time when a new thread is created and there you can change the priority of the created thread.
Inside the DLL
The primary use of this DLL is to get a notification when a new thread is created. When a new thread is created, the
DllMain function will be invoked with
DLL_PROCESS_ATTACH as the value of its second parameter that is the reason for call.
Here, you can change the priority of the current thread using the
SetThreadPriority() API. In this way, your
DllMain function can be such as the one given below.
BOOL APIENTRY DllMain( HMODULE hModule,
if( !SetThreadPriority( GetCurrentThread(), THREAD_PRIORITY_HIGHEST))
// Error case. Handle as applicable.
MessageBox( 0, L"SetThreadPriority failed", L"Priority", 0 );
You can give any thread priority for the thread as represented by the second parameter to the
Inside the EXE
This is the application in which you launch the target application "prime 95" and inject the above created DLL.
Below code shows how to start your executable in suspended mode.
// Launch the "Prime 95.exe"
memset( &stStartupInfo, 0, sizeof( stStartupInfo ));
memset( &stProcessInfo, 0, sizeof( stProcessInfo ));
stStartupInfo.cb = sizeof(stStartupInfo);
bool bSuccess = CreateProcess( L"c:\\Prime 95.exe", // Give full path of the application.
As the next step, use the
CreateRemoteThread() API to inject the above created DLL. Here is a good example on how to make use of this API for injecting a DLL to another process.