Making a program remember it's priority

By Vehementi ยท 11 replies
Jan 14, 2003
  1. Hello all,

    I'm wondering if there's anything I can do to make a program, when automatically started, to resume a preset priority for itself. This is Windows XP, of course. The program in question uses alot of CPU cycles over a long period of time, and is by default set to 'Normal'. This of course slows my system down horribly and I always have to set it down to Low. Any way I can make it automatically go to Low? I'm sure there's some registry entry that I can use, anyone got any ideas?

    Thanks in advance
  2. Rick

    Rick TechSpot Staff Posts: 4,572   +65

    Well, you could make a shortcut. This is a little idea of mine actually, rather the usual batch file that has been widely spread on the net.

    Just make a shortcut, and instead of making it "C:\notepad.exe", make it "C:\WINDOWS\system32\cmd.exe /c START /low C:\windows\notepad.exe"

    The key here is the cmd.exe, START and the path to the program.

    "C:\WINDOWS\system32\cmd.exe" = Opens the command prompt
    "/c START /low" prepares to run the program in low priority

    "C:\notepad.exe" = opens notepad.

    If you do not want to see the command prompt when you run the program, right click on the shortcut after you make it and adjust the properties. You can make it start off-screen by choosing the pixels down and right that is starts in the shortcut. I usually set mine to 2000x2000 so it is off screen.
  3. Vehementi

    Vehementi TechSpot Paladin Topic Starter Posts: 2,704

    Nice - I got it to work after I removed the spaces from the path. Thanks Rick! I'll just pin it to my start menu.
  4. Rick

    Rick TechSpot Staff Posts: 4,572   +65

    I forgot to mention that you cannot use quotes for paths, so that means all of your paths have to be strictly alpha-numeric or MSDOS compatible.
  5. Justin

    Justin TS Rookie Posts: 942

    On a side note, Rick, do you know how, in 2k/XP, to launch an app with affinity towards a specific CPU? For instance, to remove its affinity from cpu 0 and only let it execute under cpu 1, from the command prompt?
  6. Rick

    Rick TechSpot Staff Posts: 4,572   +65

    Wish I did know, but since I'm not exposed to dual CPU setups, I've never bothered looking - That is - Until now! I will post back with any leads I find on how to appropriate selective CPU usage.
  7. Rick

    Rick TechSpot Staff Posts: 4,572   +65

    Unfortunatley, I have not been able to find anything.

    If it is possible to control CPU affinity from command prompt, then it should be doable in a shortcut liek the one I gave Vehementi. You would have to add the proper command and switch to the shortcut.

    But I was unable to find any command that will change CPU affinity from the console.
  8. Negative_Pulse

    Negative_Pulse TS Rookie Posts: 16

    Hey Rick thanks allot for that tip. Now i can run my games in high priority. :D
  9. Adron

    Adron TS Rookie

    A rather late reply, but still, it didn't take too long to whip up a tool to start a program with affinity and priority as arguments:

    Download from if you still need it!

    #include <windows.h>
    int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR lpCmdLine, int nCmdShow)
    	char *p = lpCmdLine;
    	char *args[3];
    	int n = 0;
    	while(*p) {
    		while(*p == ' ')
    		args[n++] = p;
    		if(n == 3)
    		while(*p && *p != ' ')
    	if(n != 3) {
    			"Prioaff by Adron\n\n"
    			"A simple tool to start a process with a given\n"
    			"priority and affinity\n\n"
    			"prioaff <priority> <affinity> <executable> [arguments]\n"
    			"priority: 0..3 for idle..realtime\n"
    			"affinity: binary process affinity mask\n\n"
    			"You are free to use this program as you please.\n"
    			"Please drop me a message and let me know\n"
    			"if you're making a derived work from it.\n\n"
    			"As always, there are no express or implied\n"
    			"warranties as to the functionality\n"
    			"of this application!", "Prioaff", MB_OK);
    		return 1;
    	DWORD priority = strtoul(args[0], 0, 10);
    	DWORD affinity = strtoul(args[1], 0, 2);
    	DWORD processmask, systemmask;
    	GetProcessAffinityMask(GetCurrentProcess(), &processmask, &systemmask);
    	if(priority > 3) {
    		MessageBox(0, "Invalid priority value!", "Prioaff", MB_OK);
    		return 1;
    	if((affinity & processmask) != affinity) {
    		MessageBox(0, "Invalid affinity value!", "Prioaff", MB_OK);
    		return 1;
    	ZeroMemory(&si, sizeof si);
    	si.cb = sizeof si;
    	si.wShowWindow = nCmdShow;
    	BOOL success = CreateProcess(0, args[2], 0, 0, 0, CREATE_SUSPENDED | priorities[priority], 0, 0, &si, &pi);
    	if(!success) {
    		char message[128];
    		wsprintf(message, "CreateProcess failed, error: %d\n", GetLastError());
    		MessageBox(0, message, "Prioaff", MB_OK);
    		return 0;
    	success = SetProcessAffinityMask(pi.hProcess, affinity);
    	if(!success) {
    		char message[128];
    		wsprintf(message, "SetProcessAffinityMask failed, error: %d\n", GetLastError());
    		MessageBox(0, message, "Prioaff", MB_OK);
    	return 0;
  10. rudywww

    rudywww TS Rookie

    nope, "'s can be used. for instance for photoshop:
    C:\WINDOWS\system32\cmd.exe /c start "lowered priority shortcut to Adobe Photoshop" /belownormal "C:\Program Files\Adobe\Adobe Photoshop"
  11. jobeard

    jobeard TS Ambassador Posts: 11,128   +982

    Mircosoft (server at least) does SMP(symmetric multi-processor) support well.
    With more than one processors, the TCP processing is dedicated to the last
    CPU and services are spread across the others.

    As a general rule, users attempting to futz with affinity usually just get in the way
    and mess up the processor assignments. User selected priorities is great;
    affinity should be left to the scheduler.

    just my opinion; Jeff
  12. altheman

    altheman TS Rookie Posts: 425

    you can use imagecfg.exe. IMPORTANT: this modifies the exe slightly, so keep a spare backup.
Topic Status:
Not open for further replies.

Similar Topics

Add your comment to this article

You need to be a member to leave a comment. Join thousands of tech enthusiasts and participate.
TechSpot Account You may also...