请教各位老大! windows2000里怎么样 用rundll32 命令 让计算机休眠阿?小弟 正在研究 让计算机 自己 休眠的 程序!望 告之! 小弟感激不敬阿!先谢谢各位老大了!

解决方案 »

  1.   


    给你一个实现休眠的代码(VCBASE):void  PERR(LPTSTR szAPI, DWORD dwLastError);
    #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,并且打开了高级电源管理的休眠支持。
      

  2.   


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