zoukankan      html  css  js  c++  java
  • Windows XP快速关机

    windows XP存在关机过程卡死的BUG。下面这个程序可以解决这个问题。

    代码1

     1 #include <WINDOWS.H>
     2 
     3 #define ISTATUS BOOL
     4 #define ISTATUS_SUCCEED TRUE
     5 #define ISTATUS_FAILED FALSE
     6 
     7 ISTATUS WINAPI LoadPrivilege(LPTSTR Privilege)
     8 {
     9     HANDLE     hToken = NULL, hProcessHandle = NULL;
    10     LUID     SEDebugNameValue;
    11     TOKEN_PRIVILEGES  tkp;
    12     BOOL     retVal = ISTATUS_SUCCEED;
    13     hProcessHandle=GetCurrentProcess();
    14     if(!hProcessHandle)
    15     {
    16         retVal = ISTATUS_FAILED;
    17         goto cleanup;
    18     }
    19     if(!OpenProcessToken(hProcessHandle, TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY, &hToken))
    20     {
    21         retVal = ISTATUS_FAILED;
    22         goto cleanup;
    23     }
    24     if(!LookupPrivilegeValue(NULL, Privilege, &SEDebugNameValue))
    25     {
    26         retVal = ISTATUS_FAILED;
    27         goto cleanup;
    28     }
    29     tkp.PrivilegeCount = 1;
    30     tkp.Privileges[0].Luid = SEDebugNameValue;
    31     tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
    32     if(!AdjustTokenPrivileges(hToken, 0, &tkp, sizeof(TOKEN_PRIVILEGES), NULL, NULL))
    33     {
    34         retVal = ISTATUS_FAILED;
    35         goto cleanup;
    36     }
    37 cleanup:
    38     if(hToken != NULL) CloseHandle(hToken);
    39     if(hProcessHandle != NULL) CloseHandle(hProcessHandle);
    40     return retVal;
    41 }
    42 
    43 int WINAPI WinMain( HINSTANCE hInstance, 
    44                     HINSTANCE hPrevInstance, 
    45                     LPSTR lpCmdLine, 
    46                     int nShowCmd )
    47 {
    48     LoadPrivilege(SE_DEBUG_NAME);
    49     if(ISTATUS_FAILED == LoadPrivilege(SE_SHUTDOWN_NAME))
    50     {
    51         WinExec("shutdown -s -f -t 60",  SW_SHOW);
    52     }
    53     if( !ExitWindowsEx(EWX_POWEROFF | EWX_FORCE, 0))
    54     {
    55         ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0);
    56     }
    57     ExitProcess(0);
    58 }

    代码2(不保存用户配置直接断电,不推荐)

     1 #include <WINDOWS.H>
     2 
     3 typedef UINT (CALLBACK* LPFNDLLFUNC1)(ULONG,BOOL,BOOL,int *);
     4 
     5 int APIENTRY WinMain(HINSTANCE hInstance,
     6                      HINSTANCE hPrevInstance,
     7                      LPSTR     lpCmdLine,
     8                      int       nCmdShow)
     9 {
    10     int en;
    11     UINT nRet;
    12     
    13     LPFNDLLFUNC1 lpfnDllFunc1;
    14     
    15     lpfnDllFunc1 = (LPFNDLLFUNC1)GetProcAddress(LoadLibrary("Ntdll.dll"),"RtlAdjustPrivilege");
    16     
    17     nRet=lpfnDllFunc1(0x13,1,1,&en);
    18     
    19     if(nRet==0x0C000007C)lpfnDllFunc1(0x13,1,0,&en);
    20     
    21     
    22     GetProcAddress(LoadLibrary("Ntdll.dll"),"ZwShutdownSystem");
    23     __asm
    24     { 
    25         push 2       //ZwShutdownSystem(ShutdownPowerOff);
    26             call eax
    27     }
    28     return 0;
    29 }
  • 相关阅读:
    SGU180 Inversions(树状数组求逆序数)
    HDU 1465(错排公式)
    CodeForces 580B(尺取法)
    Entertainment Box Gym100781E(数据结构+贪心)
    Sort HDU5884(二分+多叉哈夫曼树)
    P3808 【模板】AC自动机(简单版)
    Coefficient Computation (大整数、Java解决)
    Chat Group gym101775A(逆元,组合数)
    等和的分割子集--01背包问题
    蓝桥杯手链样式
  • 原文地址:https://www.cnblogs.com/Leon5/p/2482991.html
Copyright © 2011-2022 走看看