David Chang
David Chang

Reputation: 21

kernel mode timer

How can I have a timer in kernel mode such that a specified function in my driver is called approximately every second on Windows XP and above? I should be able to use all functions (in particular ZwQuerySystemInformation) in the function. I do not need a high resolution timer or millisecond accuracy or anything like that, I just need a way to schedule a function to be run about once per second in kernel mode and it must work on all 32 bit systems windows xp and higher.

Upvotes: 2

Views: 3661

Answers (3)

Neeraj Singh
Neeraj Singh

Reputation: 609

Instead of wasting a thread, you can also use a dpc object to get a callback at dispatch level when the timer expires. Just pass it as the dpc argument for KeSetTimerEx.

Upvotes: 2

Brian
Brian

Reputation: 2813

Create a kernel timer via KeInitializeTimer.
Set the timer with KeSetTimerEx and use a period of 1s.
Create a thread in your driver.
In the thread, call KeWaitForSingleObject to wait on the timer and upon return, call your function.
Repeat.

Upvotes: 5

Sergey Podobry
Sergey Podobry

Reputation: 7189

You can use KeDelayExecutionThread within a loop in your thread.

Upvotes: 2

Related Questions