up也给分。
解决方案 »
- 如何判断一个文件是否被打开了呢?
- VS2008调用VC6生成的静态库出错
- error C2143: syntax error : missing ')' before '*'
- 谁真正明白C++,类到底是怎么回事情
- 如何写IE收藏夹?
- UDP在一个网卡多个IP地址情况下的问题
- CSDN所有需要电子书的同胞们进来,所有的电子书这里都有!
- 在vb中调用VC/ATL写的COM组件时如何调试?
- 如何通过网络播放和接收DVD (MPEG-4格式的)视频流????????
- 哪里有文件夹选择对话框(CPathDialog)控件?
- 怎样访问DLL中倒出的变量?
- 如何快速求解多Polyline的交点?(大数量级)
#define RTN_ERROR 13INT SetPower()
{
// TODO: Add your control notificationhandler code here
TOKEN_PRIVILEGES tp;
HANDLE hToken;
LUID luid; LPTSTR MachineName=NULL; // pointer to machine name if(!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES,
&hToken ))
{
PERR("OpenProcessToken", GetLastError() );
return RTN_ERROR;
} if(!LookupPrivilegeValue(MachineName, SE_SHUTDOWN_NAME, &luid)) {
PERR("LookupPrivilegeValue", GetLastError() );
return RTN_ERROR;
} tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES),
NULL, NULL ); SetSystemPowerState(FALSE,TRUE);
return 0;}
void PERR(
LPTSTR szAPI, // pointer to failed API name
DWORD dwLastError // last error value associated with API
)
{
LPTSTR MessageBuffer;
DWORD dwBufferLength; //
// TODO get this fprintf out of here!
//
fprintf(stderr,"%s error! (rc=%lu)\n", szAPI, dwLastError); if(dwBufferLength=FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
dwLastError,
LANG_NEUTRAL,
(LPTSTR) &MessageBuffer,
0,
NULL))
{ DWORD dwBytesWritten; //
// Output message string on stderr
//
WriteFile(GetStdHandle(STD_ERROR_HANDLE),
MessageBuffer,
dwBufferLength,
&dwBytesWritten,
NULL); //
// free the buffer allocated by the system
//
LocalFree(MessageBuffer);
}
}注意:此函数只运行于Windows 2000/XP,并且打开了高级电源管理的休眠支持。
BOOLEAN SetSuspendState(
BOOL Hibernate,
BOOL ForceCritical,
BOOL DisableWakeEvent
);Parameters
Hibernate
[in] If this parameter is TRUE, the system hibernates. If the parameter is FALSE, the system is suspended.
ForceCritical
[in] If this parameter is TRUE, the system suspends operation immediately; if it is FALSE, the system broadcasts a PBT_APMQUERYSUSPEND event to each application to request permission to suspend operation.
DisableWakeEvent
[in] If this parameter is TRUE, the system disables all wake events. If the parameter is FALSE, any system wake events remain enabled.
Return Values
If the function succeeds, the return value is nonzero.If the function fails, the return value is zero. To get extended error information, call GetLastError.Res
An application may use SetSuspendState to transition the system from the working state to the standby (sleep), or optionally, hibernate (S4) state. This function is similar to the SetSystemPowerState function.Requirements
Client: Included in Windows XP, Windows 2000 Professional, Windows Me, and Windows 98.
Server: Included in Windows Server 2003 and Windows 2000 Server.
Header: Declared in Powrprof.h.
Library: Use Powrprof.lib.