zoukankan      html  css  js  c++  java
  • Windows快速关机与重启

    #include <windows.h>
    
    int WINAPI WinMain( __in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance, __in_opt LPSTR lpCmdLine, __in int nShowCmd )
    {
        int SE_SHUTDOWN_PRIVILEGE = 0x13;
        typedef int (WINAPI *PFNRtlAdjustPrivilege)( INT, BOOL, BOOL, BOOL* );
        typedef int (WINAPI *PFNZwShutdownSystem)( INT );
    
        HMODULE hModule = LoadLibrary( TEXT("ntdll.dll") );
        if( hModule != NULL)
        {
            PFNRtlAdjustPrivilege pfnRtlAdjustPrivilege = (PFNRtlAdjustPrivilege)GetProcAddress( hModule, "RtlAdjustPrivilege" );
            PFNZwShutdownSystem pfnZwShutdownSystem = (PFNZwShutdownSystem)GetProcAddress( hModule, "ZwShutdownSystem" );
            if( pfnRtlAdjustPrivilege != NULL &&
                pfnZwShutdownSystem != NULL )
            {
                BOOL bEnabled = 0;
                int nResult = pfnRtlAdjustPrivilege( SE_SHUTDOWN_PRIVILEGE,
                                                  TRUE, TRUE, &bEnabled );
                if( nResult == 0xC000007C )
                nResult = pfnRtlAdjustPrivilege( SE_SHUTDOWN_PRIVILEGE,
                                              TRUE, FALSE, &bEnabled );
                nResult = pfnZwShutdownSystem( 0 );
                //快速关闭系统 = 0;
                //快速重启 = 1;
                //快速关机 = 2;
            }
        }
    }
    
  • 相关阅读:
    C语言第三天,《常量指针和指针常量》
    树莓派系统烧入总结
    c 语言第一天
    7. Vue
    6. Vue
    5. Vue
    4. Vue
    3. Vue
    1. Vue
    2. Vue
  • 原文地址:https://www.cnblogs.com/LinuxHunter/p/1885832.html
Copyright © 2011-2022 走看看