We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Can machine suspend?

dmetzler
dmetzler asked
on
Medium Priority
360 Views
Last Modified: 2013-12-03
How can it be determined if a machine is capable of suspending?
Comment
Watch Question

Commented:
What do you mean?  Do you mean the low-power screen saver?  that can be obtained from SystemParemetersInfo().

Author

Commented:
No - laptop machines can suspend (sleep).  I know how to place a machine in suspend mode (if it can).  I want to query a system to see if it is capable of suspending.  (Laptop machines have an additional Start Menu item below Shutdown for Suspend)

Commented:
I don't see a direct way.  But if there isn't a direct way, you might try using GetSystemPowerStatus() and looking to see if the computer has a battery.
WDB

Commented:
Check for the follwing Registry entry

HKEY_LOCAL_MACHINE\Enum\Root\*PNP0C05\0000\APMMenuSuspend

If it's there the system is cabable of suspending.

Author

Commented:
I have just checked the key on my desktop machine:

HKEY_LOCAL_MACHINE\Enum\Root\*PNP0C05\0000\APMMenuSuspend

This value shows up as 01, but this machine cannot suspend, nor does it have a Start Menu suspend option.

Commented:
I've not found it to be 100% reliable but the following code uses the SetSystemPowerState() function to try and do a suspend.  The problem with reliability is that not all laptops support the APM power functions.  Many provide their own interface to their own power management protocol and make it look like it's the same as Windows.  The problem is then that Windows only knows how to deal with APM.

void CRebootDialog::OnClickedSuspend()
{
    if(!SetSystemPowerState(FALSE, TRUE)){
        AfxMessageBox("Failed to initiate SUSPEND - Does your system support APM functions?");
        EndDialog(IDC_APMFAILED);
    }
    else{
        EndDialog(IDC_SUSPENDOK);
    }
}

Author

Commented:
I need to know if this available BEFORE the machine attempts to suspend, as I want to make some options unavailable.

Commented:
Use an ACCESSTIMEOUT structure when calling the SystemParametersInfo() function with the uiAction parameter set to the SPI_GETACCESSTIMEOUT. You will be interested in some of the other functions/uiAction parameters available to SystemParametersInfo().

Author

Commented:
The ACCESSTIMEOUT structure and SystemParametersInfo seem to be used with the accessibility features, if installed, and not for a suspend.

Commented:
The WM_POWERBROADCAST message is sent to an application to notify it of power-management events.

dwPowerEvent = (DWORD) wParam;
dwData = (DWORD) lParam;
 
PBT_APMBATTERYLOW
 Battery power is low.
 
PBT_APMOEMEVENT
 OEM-defined event occurred.
 
PBT_APMPOWERSTATUSCHANGE
 Power status has changed.
 
PBT_APMQUERYSUSPEND
 Request for permission to suspend.
 
PBT_APMQUERYSUSPENDFAILED
 Suspension request denied.
 
PBT_APMRESUMECRITICAL
 Operation resuming after critical suspension.
 
PBT_APMRESUMESUSPEND
 Operation resuming after suspension.
 
PBT_APMSUSPEND
 
Can be used to determine if a suspend is goning to occur and you have time to do work or deny the suspension with BROADCAST_QUERY_DENY.


WM_POWERBROADCAST is sent by VPOWERD.VXD. There is a discussion in the 95DDK (KERNEL.DOC) about the VPOWERD handler services. The function you would want to use is:DWORD _VPOWERD_Get_Power_Management_Level (void); that returns the power management level of the system =
0 - both bios and cooperative power management on.
1 - bios power management on.
2 - power management off.

So, use LoadLibrary() to get the VPOWERD.VXD and GetProcAddress() to get _VPOWERD_Get_Power_Management_Level() and call the address of this function to get the return.

But I haven't seen an actual function in the SDK that will get the information you want.
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

Author

Commented:
Great!  Thanks!

Don
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.