What's new

About changuing thread priorities...

NeTo

Emu_64 HiP Coder
Just to ask if there is a way to change a thread priority of an already running process in Windows (any version).

I thought it would be easy. But there's no info on the .net (at least as far i have searched) besides sites that tell you how to set the thread priority of a thread you create.

I don't know if that's a limitation of the language (Visual Basic 6) or a limitation of the OS itself...

If thread priorities of any process can be altered in any programming language please tell me, cos I'm starting to have nightmares about that.
 

tooie

New member
what process you changing .. any way look at
OpenProcess - get Handle to the process .. may need to find it out
SetPriorityClass - Change the priority of the handle to the process you got
 
OP
NeTo

NeTo

Emu_64 HiP Coder
Yep I have used those two without probs.

I would want to know if there's something smilar with Threads (not processes). There's the SetThreadPriority API, but i need a thread handle in order to use it.
 

Doomulation

?????????????????????????
Yes, I think I remember an api named GetCurrentThreadID...since you're using VB, check the api viewer utility. It lists about all windows apis...how to use them with vb, i don't know...apis are mainly for c++ and c, but...

Oh and VB6 does _NOT_ support support threads nor changing priorities. If you wish to change priorities, you must use windows api. Threads aren't supported no matter what, even with windows api, so don't even think about trying ;)

On a second note, VB .net supports this, if you're intrested :)
 
OP
NeTo

NeTo

Emu_64 HiP Coder
Doomulation said:
Yes, I think I remember an api named GetCurrentThreadID...since you're using VB, check the api viewer utility. It lists about all windows apis...how to use them with vb, i don't know...apis are mainly for c++ and c, but...

Oh and VB6 does _NOT_ support support threads nor changing priorities. If you wish to change priorities, you must use windows api. Threads aren't supported no matter what, even with windows api, so don't even think about trying ;)

On a second note, VB .net supports this, if you're intrested :)

Yep I know it's Windows API not VB6, but VB supports them well as far as i can see. At least for processes...

blight said:
maybe there's something like GetCurrentThreadId();

Yes, there's is a GetCurrentThreadID API. But to use SetThreadPriority I need to know the thread handle (not the id), that's where my problem resides...
 

Doomulation

?????????????????????????
There's function to get handle by process ids, too...well, I don't know, it might not help since there's several threads...
 
OP
NeTo

NeTo

Emu_64 HiP Coder
Doomulation said:
There's function to get handle by process ids, too...well, I don't know, it might not help since there's several threads...

but it retrieves a handle to the Process, not to the threads
 
OP
NeTo

NeTo

Emu_64 HiP Coder
Uhm... funny, thread32first and thread32next doesn't appear anywhere in the vb6 documentation.

Unfortunately, the thread32entry type they return, only tells you the ID of the thread, not the handle
 
OP
NeTo

NeTo

Emu_64 HiP Coder
OP
NeTo

NeTo

Emu_64 HiP Coder
Just discovered there is a OpenThread API. Unluckily it works only in Windows Me/2000/XP.

I tried the DebugActiveProcess function in the link you posted tooie. But it works fine only on Windows XP (on other windows versions there is no way to stop the debugging rather than closing the process). Anyway thanx for your help
 

tooie

New member
I can think of ways of doing it in c++ if your starting the target process .. but it would not work in VB
 

tooie

New member
it is a program I wrote to trace all api calls being executed .. basicly you walk the import table and modify the program so it notifies the host program on any/all api you care about .. then you can read the passed api param and and change the returned value .. or at least use it ..
 

Top