How to prevent system changes to an Sx sleep state from S0 working state in driver

Hi All,

I’m developing a PCI vedio card driver based on WDK6000.
I want to the system stay on S0 working state while our vedio card is working.So when a user cliked “sleep” from the “start” menu,our driver can prevent the system changes to an Sx sleep state from S0 working state.

How can realize this?Is there any useful WDK function to realize this?

Any help is appreciated.Thanks.

Best Regards
Zhou ChengJun

Look - I can use google, search this list and come up with the answer:

"Use PoRegisterSystemState in the driver, something like this

1 PVOID hPower = PoRegisterSystemState(NULL, ES_SYSTEM_REQUIRED |
ES_CONTINUOUS);
2 …do your work (probably asynchronously)…
3 when done, call PoUnregisterSystemState(hPower);

d"

Why don’t folks do this?

On Jan 9, 2008 9:26 PM, wrote:

> Hi All,
>
> I’m developing a PCI vedio card driver based on WDK6000.
> I want to the system stay on S0 working state while our vedio card is
> working.So when a user cliked “sleep” from the “start” menu,our driver can
> prevent the system changes to an Sx sleep state from S0 working state.
>
> How can realize this?Is there any useful WDK function to realize this?
>
> Any help is appreciated.Thanks.
>
> Best Regards
> Zhou ChengJun
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>


Mark Roddy

Ok, I will try to do this,thanks.

Mark Roddy wrote:

Look - I can use google, search this list and come up with
the answer. Why don’t folks do this?

Because they know you will copy and paste the code for them.

xxxxx@yahoo.com.cn wrote:

I’m developing a PCI vedio card driver based on WDK6000.
I want to the system stay on S0 working state while our vedio card is working.So when a user cliked “sleep” from the “start” menu,our driver can prevent the system changes to an Sx sleep state from S0 working state.

That is not an acceptable answer. If the user wants his computer to go
to sleep, your driver should not try to prevent it. It is not YOUR
compter, after all. It is the USER’S computer. If he wants to sleep,
he must have a good reason. What if he is closing the lid on his laptop
to climb on a plane? If you prevent the sleep, his batteries will be dead.

Because of this, in many cases, Vista will override your driver’s
decision anyway. You need to figure out how to handle power transitions.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

If he follows the hints I provided he should be fine. The driver can
register when it is busy and when it is not busy. The user should still be
able to put the system to sleep.

On Jan 10, 2008 1:15 PM, Tim Roberts wrote:

> xxxxx@yahoo.com.cn wrote:
> > I’m developing a PCI vedio card driver based on WDK6000.
> > I want to the system stay on S0 working state while our vedio card is
> working.So when a user cliked “sleep” from the “start” menu,our driver can
> prevent the system changes to an Sx sleep state from S0 working state.
> >
>
> That is not an acceptable answer. If the user wants his computer to go
> to sleep, your driver should not try to prevent it. It is not YOUR
> compter, after all. It is the USER’S computer. If he wants to sleep,
> he must have a good reason. What if he is closing the lid on his laptop
> to climb on a plane? If you prevent the sleep, his batteries will be
> dead.
>
> Because of this, in many cases, Vista will override your driver’s
> decision anyway. You need to figure out how to handle power transitions.
>
> –
> Tim Roberts, xxxxx@probo.com
> Providenza & Boekelheide, Inc.
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>


Mark Roddy

If I remember correctly, PoRegisterSystemState() only influences automatic power state changes. OP asked specificaly how to avoid user originated changes where it should have no effect.

Best regards,

Michal Vodicka
UPEK, Inc.
[xxxxx@upek.com, http://www.upek.com]


From: xxxxx@lists.osr.com[SMTP:xxxxx@lists.osr.com] on behalf of Mark Roddy[SMTP:xxxxx@hollistech.com]
Reply To: Windows System Software Devs Interest List
Sent: Thursday, January 10, 2008 8:46 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] How to prevent system changes to an Sx sleep state from S0 working state in driver

If he follows the hints I provided he should be fine. The driver can register when it is busy and when it is not busy. The user should still be able to put the system to sleep.

On Jan 10, 2008 1:15 PM, Tim Roberts > wrote:
>
>
> xxxxx@yahoo.com.cn mailto:xxxxx wrote:
> > I’m developing a PCI vedio card driver based on WDK6000.
> > I want to the system stay on S0 working state while our vedio card is working.So when a user cliked “sleep” from the “start” menu,our driver can prevent the system changes to an Sx sleep state from S0 working state.
> >
>
> That is not an acceptable answer. If the user wants his computer to go
> to sleep, your driver should not try to prevent it. It is not YOUR
> compter, after all. It is the USER’S computer. If he wants to sleep,
> he must have a good reason. What if he is closing the lid on his laptop
> to climb on a plane? If you prevent the sleep, his batteries will be dead.
>
> Because of this, in many cases, Vista will override your driver’s
> decision anyway. You need to figure out how to handle power transitions.
>
> –
> Tim Roberts, xxxxx@probo.com mailto:xxxxx
> Providenza & Boekelheide, Inc.
>
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http:
>
> To unsubscribe, visit the List Server section of OSR Online at http:
>
>
>
>
>
> –
> Mark Roddy — NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
></http:></http:></mailto:xxxxx></mailto:xxxxx>

The hint you provided (and the reference to my previous post) prevent the machine from idling out and sleeping on its own. It does nothing to prevent the user from manually initiating sleep on his own. As someone else already mentioned, the driver should not prevent the transition from occurring. Bad results may happen.

d

From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Mark Roddy
Sent: Thursday, January 10, 2008 11:46 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] How to prevent system changes to an Sx sleep state from S0 working state in driver

If he follows the hints I provided he should be fine. The driver can register when it is busy and when it is not busy. The user should still be able to put the system to sleep.
On Jan 10, 2008 1:15 PM, Tim Roberts > wrote:
xxxxx@yahoo.com.cnmailto:xxxxx wrote:
> I’m developing a PCI vedio card driver based on WDK6000.
> I want to the system stay on S0 working state while our vedio card is working.So when a user cliked “sleep” from the “start” menu,our driver can prevent the system changes to an Sx sleep state from S0 working state.
>

That is not an acceptable answer. If the user wants his computer to go
to sleep, your driver should not try to prevent it. It is not YOUR
compter, after all. It is the USER’S computer. If he wants to sleep,
he must have a good reason. What if he is closing the lid on his laptop
to climb on a plane? If you prevent the sleep, his batteries will be dead.

Because of this, in many cases, Vista will override your driver’s
decision anyway. You need to figure out how to handle power transitions.


Tim Roberts, xxxxx@probo.commailto:xxxxx
Providenza & Boekelheide, Inc.


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer


Mark Roddy — NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer</mailto:xxxxx></mailto:xxxxx>

The thread I referred to included the complete explanation of this. I left
it as an exercise for the OP to google the rest of the research. This
question is asked and answered monthly if not weekly.

On Jan 10, 2008 4:22 PM, Michal Vodicka wrote:

> If I remember correctly, PoRegisterSystemState() only influences automatic
> power state changes. OP asked specificaly how to avoid user originated
> changes where it should have no effect.
>
> Best regards,
>
> Michal Vodicka
> UPEK, Inc.
> [xxxxx@upek.com, http://www.upek.com]
>
>
> > ----------
> > From: xxxxx@lists.osr.com[
> SMTP:xxxxx@lists.osr.com] on behalf of Mark Roddy[
> SMTP:xxxxx@hollistech.com]
> > Reply To: Windows System Software Devs Interest List
> > Sent: Thursday, January 10, 2008 8:46 PM
> > To: Windows System Software Devs Interest List
> > Subject: Re: [ntdev] How to prevent system changes to an Sx sleep
> state from S0 working state in driver
> >
> > If he follows the hints I provided he should be fine. The driver can
> register when it is busy and when it is not busy. The user should still be
> able to put the system to sleep.
> >
> >
> > On Jan 10, 2008 1:15 PM, Tim Roberts > xxxxx@probo.com>> wrote:
> >
> >
> > xxxxx@yahoo.com.cn mailto:xxxxx wrote:
> > > I’m developing a PCI vedio card driver based on WDK6000.
> > > I want to the system stay on S0 working state while our vedio
> card is working.So when a user cliked “sleep” from the “start” menu,our
> driver can prevent the system changes to an Sx sleep state from S0 working
> state.
> > >
> >
> > That is not an acceptable answer. If the user wants his computer
> to go
> > to sleep, your driver should not try to prevent it. It is not
> YOUR
> > compter, after all. It is the USER’S computer. If he wants to
> sleep,
> > he must have a good reason. What if he is closing the lid on his
> laptop
> > to climb on a plane? If you prevent the sleep, his batteries will
> be dead.
> >
> > Because of this, in many cases, Vista will override your driver’s
> > decision anyway. You need to figure out how to handle power
> transitions.
> >
> > –
> > Tim Roberts, xxxxx@probo.com mailto:xxxxx
> > Providenza & Boekelheide, Inc.
> >
> >
> >
> > —
> > NTDEV is sponsored by OSR
> >
> > For our schedule of WDF, WDM, debugging and other seminars visit:
> > http:
> >
> > To unsubscribe, visit the List Server section of OSR Online at <
> http://www.osronline.com/page.cfm?name=ListServer&gt;
> >
> >
> >
> >
> >
> > –
> > Mark Roddy — NTDEV is sponsored by OSR For our schedule of WDF, WDM,
> debugging and other seminars visit: http://www.osr.com/seminars To
> unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
> >
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>


Mark Roddy</http:></mailto:xxxxx></mailto:xxxxx>

Thank you all for your enthusiastic replies.Well,when I used PoRegisterSystemState() or PoSetSystemState() in my driver,it took no effect.When I clicked “sleep” from the “Start” menu,the system sleeped also.Our vedio card is used for vedio monitor system,it must keep working state all the time,but Vista OS default "turn into sleep state " time is “1 hour”,we must select the "turn into sleep state " time to “never” or else our card can not work when the system turn into “sleep” state 1 hour later.My original intention is our driver can prevent the system changes to an Sx sleep state from S0 working state when our vedio card begin to work.To do this can prevent User’s wrong operation–clicking “sleep” from the “Start” menu while our vedio card is working or User forget to select the "turn into sleep state " time to “never”.

Is there any other useful WDK function to realize this?

Any help is appreciated.Thanks.

Best Regards
Zhou ChengJun

> Is there any other useful WDK function to realize this?

No, this is not supported by Windows to avoid the laptops from continue running
when the lid is closed.

So, just document this and assume the user is not this stupid.


Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

The vista system is working as specified. If the user demands sleep, the
system will sleep. If the laptop lid is closed, the system will sleep.

On Jan 14, 2008 2:17 AM, wrote:

> Thank you all for your enthusiastic replies.Well,when I used
> PoRegisterSystemState() or PoSetSystemState() in my driver,it took no
> effect.When I clicked “sleep” from the “Start” menu,the system sleeped
> also.Our vedio card is used for vedio monitor system,it must keep working
> state all the time,but Vista OS default "turn into sleep state " time is “1
> hour”,we must select the "turn into sleep state " time to “never” or else
> our card can not work when the system turn into “sleep” state 1 hour
> later.My original intention is our driver can prevent the system changes
> to an Sx sleep state from S0 working state when our vedio card begin to
> work.To do this can prevent User’s wrong operation–clicking “sleep” from
> the “Start” menu while our vedio card is working or User forget to select
> the "turn into sleep state " time to “never”.
>
> Is there any other useful WDK function to realize this?
>
> Any help is appreciated.Thanks.
>
> Best Regards
> Zhou ChengJun
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>


Mark Roddy

xxxxx@yahoo.com.cn wrote:

Thank you all for your enthusiastic replies.Well,when I used PoRegisterSystemState() or PoSetSystemState() in my driver,it took no effect.When I clicked “sleep” from the “Start” menu,the system sleeped also.Our vedio card is used for vedio monitor system,it must keep working state all the time,but Vista OS default "turn into sleep state " time is “1 hour”,we must select the "turn into sleep state " time to “never” or else our card can not work when the system turn into “sleep” state 1 hour later.My original intention is our driver can prevent the system changes to an Sx sleep state from S0 working state when our vedio card begin to work.To do this can prevent User’s wrong operation–clicking “sleep” from the “Start” menu while our vedio card is working or User forget to select the "turn into sleep state " time to “never”.

Is there any other useful WDK function to realize this?

No. It is NOT UP TO YOU to decide that this was a user error. If the
user clicks Sleep from the Start menu, then the system is going to
sleep, and you cannot stop it, nor should you want to. Instead, you
need to take whatever steps you need to take to make sure you can
survive the sleep state. If it was a user error, they’ll figure it out
pretty darned quick.

Too many people think that I bought my computer for no other purpose
than to run their software or hardware. HP is one of the worst, Adobe
is just as bad. Be a good neighbor.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Well,thank you all.But I still in doubt:our previous driver based on WDM was built with DriverStudio,It can be installed in 2000/XP OS,It can prevent system changes to an Sx sleep state from S0 working state when our vedio card begin to work.When user clicks Standby from the Start menu while our vedio card is working,the system pop-up a warning(system standby failed) “the device drive is preventing computer turning into standby state”,and then the system is in S0 state also.
How XP OS realize this?Why Vista can not?I searched the Internet,somebody say:in Win98 OS,the driver returns “STATUS_UNSUCCESSFUL” to pIrp->IoStatus.Status when it receives IRP_MN_QUERY_POWER,this can prevent system changes to an Sx sleep state from S0 working state in driver.If it’s right,how can realize this in WDK6000?

This was this feature is handled was explicitly changed in Vista to
prevent precisely what you are trying to do. The reason has already
been stated several time - when a user explicitly chooses to hibernate
from the menu, or implicitly by closing the laptop, the number one
priority is that this request is honored to conserved battery life.
What you wish to do will allow your driver to override this and
inadvertently kill the battery, which is a trade damn close to no one
wants. I hear you on the popup dialog box, but a user will not see that
if he or she just closes the lid.

There is no way to do what you want to do on Vista.

mm

xxxxx@yahoo.com.cn wrote:

Well,thank you all.But I still in doubt:our previous driver based on WDM was built with DriverStudio,It can be installed in 2000/XP OS,It can prevent system changes to an Sx sleep state from S0 working state when our vedio card begin to work.When user clicks Standby from the Start menu while our vedio card is working,the system pop-up a warning(system standby failed) “the device drive is preventing computer turning into standby state”,and then the system is in S0 state also.
How XP OS realize this?Why Vista can not?I searched the Internet,somebody say:in Win98 OS,the driver returns “STATUS_UNSUCCESSFUL” to pIrp->IoStatus.Status when it receives IRP_MN_QUERY_POWER,this can prevent system changes to an Sx sleep state from S0 working state in driver.If it’s right,how can realize this in WDK6000?

Martin,

Certainly the stock answer is “Don’t do that” because it will confuse the user…

However, there are legitimate reasons why this sort of behavior might be desirable or essential. For example, in industrial or measurement applications, etc.

I don’t know what the Ops product is, but there may be good reason for needing this feature.

(Or there might not…)

If the answer is “It’s not possible at all”, then that’s the end of it, of course.

Thomas F. Divine

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:bounce-311461-
xxxxx@lists.osr.com] On Behalf Of Martin O’Brien
Sent: Monday, January 14, 2008 10:48 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] How to prevent system changes to an Sx sleep state
from S0 working state in driver

This was this feature is handled was explicitly changed in Vista to
prevent precisely what you are trying to do. The reason has already
been stated several time - when a user explicitly chooses to hibernate
from the menu, or implicitly by closing the laptop, the number one
priority is that this request is honored to conserved battery life.
What you wish to do will allow your driver to override this and
inadvertently kill the battery, which is a trade damn close to no one
wants. I hear you on the popup dialog box, but a user will not see
that
if he or she just closes the lid.

There is no way to do what you want to do on Vista.

mm

xxxxx@yahoo.com.cn wrote:
> Well,thank you all.But I still in doubt:our previous driver based on
WDM was built with DriverStudio,It can be installed in 2000/XP OS,It
can prevent system changes to an Sx sleep state from S0 working state
when our vedio card begin to work.When user clicks Standby from the
Start menu while our vedio card is working,the system pop-up a
warning(system standby failed) “the device drive is preventing computer
turning into standby state”,and then the system is in S0 state also.
> How XP OS realize this?Why Vista can not?I searched the
Internet,somebody say:in Win98 OS,the driver returns
“STATUS_UNSUCCESSFUL” to pIrp->IoStatus.Status when it receives
IRP_MN_QUERY_POWER,this can prevent system changes to an Sx sleep state
from S0 working state in driver.If it’s right,how can realize this in
WDK6000?
>


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

In vista, it is not possible for a driver to fail an Sx transition. Previous to vista, you could do this by failing IRP_MN_QUERY_POWER/Sx, but in vista even if you fail this irp, the Sx transition will still occur

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Thomas F. Divine
Sent: Monday, January 14, 2008 8:21 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How to prevent system changes to an Sx sleep state from S0 working state in driver

Martin,

Certainly the stock answer is “Don’t do that” because it will confuse the user…

However, there are legitimate reasons why this sort of behavior might be desirable or essential. For example, in industrial or measurement applications, etc.

I don’t know what the Ops product is, but there may be good reason for needing this feature.

(Or there might not…)

If the answer is “It’s not possible at all”, then that’s the end of it, of course.

Thomas F. Divine

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:bounce-311461-
xxxxx@lists.osr.com] On Behalf Of Martin O’Brien
Sent: Monday, January 14, 2008 10:48 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] How to prevent system changes to an Sx sleep state
from S0 working state in driver

This was this feature is handled was explicitly changed in Vista to
prevent precisely what you are trying to do. The reason has already
been stated several time - when a user explicitly chooses to hibernate
from the menu, or implicitly by closing the laptop, the number one
priority is that this request is honored to conserved battery life.
What you wish to do will allow your driver to override this and
inadvertently kill the battery, which is a trade damn close to no one
wants. I hear you on the popup dialog box, but a user will not see
that
if he or she just closes the lid.

There is no way to do what you want to do on Vista.

mm

xxxxx@yahoo.com.cn wrote:
> Well,thank you all.But I still in doubt:our previous driver based on
WDM was built with DriverStudio,It can be installed in 2000/XP OS,It
can prevent system changes to an Sx sleep state from S0 working state
when our vedio card begin to work.When user clicks Standby from the
Start menu while our vedio card is working,the system pop-up a
warning(system standby failed) “the device drive is preventing computer
turning into standby state”,and then the system is in S0 state also.
> How XP OS realize this?Why Vista can not?I searched the
Internet,somebody say:in Win98 OS,the driver returns
“STATUS_UNSUCCESSFUL” to pIrp->IoStatus.Status when it receives
IRP_MN_QUERY_POWER,this can prevent system changes to an Sx sleep state
from S0 working state in driver.If it’s right,how can realize this in
WDK6000?
>


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Ok,I understand thoroughly now.Thank you all.

> How XP OS realize this?

By failing MJ_POWER/System/Query IRPs.

Why Vista can not?

Microsoft removed this feature from Vista, considering it evil.


Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

Thomas F. Divine wrote:

Certainly the stock answer is “Don’t do that” because it will confuse the user…

However, there are legitimate reasons why this sort of behavior might be desirable or essential. For example, in industrial or measurement applications, etc.

Yes, but, in that case the USER will have configured his machine so as
to prevent hibernation or sleep. The key point is that it is NOT the
driver writer’s job to decide this. We can include release notes that
point out that “oh by the way, it would be bad for your capture session
if your machine were to go to sleep while capturing, and here’s how to
prevent that.”

This is exactly the same thing as Nero stupidly triggering an assert
when their codecs are loaded if the kernel debugger happens to be
connected. It is a driver writer deciding that he should have more
control over my computer than I do.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.