请教各位老大! windows2000里怎么样 用rundll32 命令 让计算机休眠阿?

corlorstone 2003-10-19 05:42:08
请教各位老大! windows2000里怎么样 用rundll32 命令 让计算机休眠阿?

小弟 正在研究 让计算机 自己 休眠的 程序!

望 告之! 小弟感激不敬阿!

先谢谢各位老大了!
...全文
41 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
yifengling0 2003-12-18
  • 打赏
  • 举报
回复

SetSuspendState

The SetSuspendState function suspends the system by shutting power down. Depending on the Hibernate parameter, the system either enters a suspend (sleep) state or hibernation (S4).


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.

Remarks
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.




yifengling0 2003-12-18
  • 打赏
  • 举报
回复

给你一个实现休眠的代码(VCBASE):

void PERR(LPTSTR szAPI, DWORD dwLastError);
#define RTN_ERROR 13

INT 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,并且打开了高级电源管理的休眠支持。


15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧