VB6 Programmers!!!

letdown427

Golden Member
Jan 3, 2006
1,594
1
0
How would I go about setting the CPU affinity for a process? As in, as if I'd gone into task manager, and set the CPU affinity of say, explorer.exe to 0

I presume I'm going to need api calls and such, any help would be appreciated.


If not, does anyone know how to set process affinitys in the registry? I've found the relevant page on the MSDN, about the MMCSS

http://msdn.microsoft.com/library/defau...multimedia_class_scheduler_service.asp

but that registry key they refer to doesn't exist on this pc at least. I don't care so much because this is at work, and it's a Dell, so I'll just blame that for no reason, but I'm betting it won't be at home either.
 

letdown427

Golden Member
Jan 3, 2006
1,594
1
0
Thanks very much for the code. Thing is, I'm a bit new to programming, and so don't know how to actually use that to get the results I want. :(

If you could code an example, that literaly just sets iexplore.exe affinity to 0, then I could use that as an example and figure out the rest. I'm sorry to be such a n00b. I've been googling for hours, and have had trouble finding a way of doing what I want.

Just a question, from task manager, a lot of the processes you can't change the affinity for, well, at least, not using task manager, I just get access denied. Would this code allow those to be controlled also or...?

Thanks so much for the response, I'm sorry I can't do it justice yet!!

James
 

igowerf

Diamond Member
Jun 27, 2000
7,697
1
76
I haven't done VB6 in a while, but I'm pretty sure you can put the two Declare Function lines in a .bas file. Right click on your project manager toolbox to add a new .bas file. Then you just Call SetProcessAffinityMask(...) in your Form Load subroutine (choose the one you need, don't call all three from xtnight's example).
 

xtknight

Elite Member
Oct 15, 2004
12,974
0
71
Just curious though: being new to programming, what do you wish to accomplish with the affinity masks? Are you making a custom Windows scheduler (process delegator) or something? Just wondering... ;)

Those processes are probably owned by SYSTEM. You'd have to obtain "admin" rights to them, which may be possible with another API command. I'm really not sure though. You'd have to request a "security descriptor" to fit your needs (obtain this from a function).

Yeah, I may be able to code you an example. But I just wonder what you are trying to do, or trying to figure out what you were really trying to ask, if you get what I mean...

Put a "Private" before the declares to put them inside your form code, or if you want them in a module, just leave it as "Declare", or put "Public Declare". Same effect.

And then call one of those affinity functions, depending on what you want to do. Modifying other processes like iexplore.exe involves some more work, like opening the process by its handle with "admin" rights, and then modifying it. There is no SetProcessAffinityMask("iexplore.exe"). MS doesn't make it easy. :(

I'd be happy to help you further.
 

letdown427

Golden Member
Jan 3, 2006
1,594
1
0
Well, since you asked lol, yeah, I basically thought it'd be a good idea to make a little program that assigns all the dull boring keep windows alive processes to one core, and then your game.exe to the other one, all by itself, thus using every available hz on that core. It seemed that that would then surely give dual cores an advantage over single cores? As say a 2.4Ghz single core, doesn't give all those 2.4Ghz to the game, it has to keep other things running, so with a dual core, you'd get the full 2.4Ghz assigne to the game.

I've found a program that I can sort of use to accomplish this. Effectively I'm just having to shell it with command line parameters for each process i want to re-assign. However, it doesn't appear to actually work, or more likely, it doesn't have the rights to do so, as from task manager, Access Denied comes up a lot when trying to set the affinitys manually.

http://www.beyondlogic.org/solutions/processutil/processutil.htm

Thats the program. I just put it in the system32 folder, so i could test it from the run dialog. Basically it's the kind of thing i was going to try and create myself, but I would have rather learnt how to make it than just used another program within mine.

Thanks very much for the help offer! I'm learning random bits of VB6 i think that's the problem, I don't know what the basics are that I should know, so I've just learnt what I need with each application I make.