[Autogenerated] let's see some examples of using these APIs in user mode,
just to see what that looks like.
So I'm going to create a console application as in previous uh courses,
going to call that simply demo just to demonstrate a few things.
Let me just put that somewhere else in a more convenient location.
So we have the normal console application as we've
seen multiple times in the past.
I'm going to just change that to include Windows 0.8 so we
have access to the Windows APIs of course.
And then I'm going to going to add S T D I O here to
use the simple printed function.
So one thing I might want to do is to look at my current priority
class and perhaps change that to something higher.
So let's just make the change,
I'm going to call the set priority class function and I'm going to use get
current process as a way to receive a handle for myself.
That's a pseudo handle to my process.
And then the priority class I'd like to have such as high priority class one of
the constants we can we can use and this is essentially it we can just try this
out because I haven't done anything special when running the process or run
launching this executable and creating a process based off that I expect the
initial priority to be normal.
So once this starts running, I've set a breakpoint just before calling.
Set priority class.
Let me open task manager this point.
Look for my demo application here.
So here's demo, you notice that the priority class is normal.
The base priority is normal.
However, one side step over this line here.
The base priority should increase to high.
So here it is.
Again, look at them or here let me press F 10 here and that's it.
You can see that demo indeed has changed too high,
which means that all the thread priorities have changed
immediately because of that change.
Let's now look at process Explorer and see what that looks like.
Now, instead of placing a breakpoint this time,
I'm going to do something slightly different by having some uh _____ variable
here so that the user can just press enter and this is because of interesting
and strange bug I just found out in Process Explorer,
so I can't really demonstrate the same thing with the breakpoints.
Let's try it in a different way.
I'm going to just use a get s here to simply wait for an
enter to be um entered by the user.
And then I'm going to make the change to the priority class.
Let me just press control of five to run this.
So here's process explore.
Let me find the demo process here, so we can see we have four threads right now.
The main thread which we expect to have and there there are other
threats here that are part of the thread pool.
Notice the priorities are exactly as we expect eight as the base
priority and perhaps some higher priority here because of some
boots that is happening right now.
So going back to our application, let's press enter here.
Let's see where that application is.
Let me remove the always on top option here and find my window here it is.
So I'm going to press enter and I expect the priorities to change
immediately notice the thread pool threads have died out which is also to be
expected because there's not much work to be available.
That is a Right now for the thread pool.
Once we do that,
notice the best parity changes immediately to 13 for
all the threats in the process.
In fact I can't really prove that right now there's just one threat but the
base priority affects all the threats in the process.
So change from 8 to 13 because of the change in the priority class,
you can see the priority class here has changed to 13 as you can see here.
If I go ahead and change that again to something else let's
say below normal then it will change to six and the spread
priority will change to six as well.
Again, dynamic priority could be slightly higher because of some priority booth,
that might be in effect Now if you wanted to do some other look up here
or some other testing here we can try to use a thread priority API as
well so we can change the thread priority the process priority to a high
but then we can also make a change to the thread priority of our current
threat in this case.
Again by using the Sudo handle.
Get current thread And then we can specify one of the seven possible values.
So we have set priority thread priority above normal.
That means plus one we have highest, which means plus two.
We have time critical, which means let's go to the situation value in this case,
that would be 15 as well.
And then we also have below normal and uh And then the lowest to get us to -2.
And we also have idle to get to the other side of
the situation value in this case, that would be one.
Let's just do a simple above normal thing here.
Just to see what that looks like for the current thread.
And of course we can use other threats that we
might be able to open handles too.
But for ourselves for the current thread it's always
possible to make these changes.
So again, let me run this And see what we get here's process explorer back here,
here's demo and you can see with demo that we have again a bunch of threads
and and the other threats will probably die out fairly soon.
Let me first just press enter to make the changes.
So you notice all the threats have party of 13 except
for the first one which has 14.
That is the one we have just changed the plus one compared to the base.