Windows 瞬間關機代碼

來源:互聯網
上載者:User

標籤:

   整理資料的時候發現的以前的代碼,本機Win7 x64 Sp1 運行直接關機,黑屏。就是利用RtlAdjustPrivilege函數提權,代碼中的注釋寫的很詳細了。用的VS2010寫的,直接編譯成x64就可以運行,直接關機了。

#include "stdafx.h"#include <Windows.h>#include <stdio.h>//定義函數原型typedef long (__fastcall *pfnRtlAdjustPrivilege64)(ULONG,ULONG,ULONG,PVOID);typedef int (* pfnZwShutdownSystem)(int);pfnRtlAdjustPrivilege64 RtlAdjustPrivilege;pfnZwShutdownSystem  ZwShutdownSystem;int _tmain(int argc, _TCHAR* argv[]){    //裝載DLL    HMODULE hModule = ::LoadLibrary(L"NTDLL.DLL");    if(hModule == NULL) {        printf("LoadLibrary error\n");        return 0;    }    //得到匯出函數的地址    RtlAdjustPrivilege = (pfnRtlAdjustPrivilege64)GetProcAddress(hModule, "RtlAdjustPrivilege");    ZwShutdownSystem = (pfnZwShutdownSystem)GetProcAddress(hModule,"ZwShutdownSystem");    if(RtlAdjustPrivilege == NULL) {        printf("GetProcAddress error \n");        return 0;    }        //取得系統版本    OSVERSIONINFO osvi;    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);    if(GetVersionEx(&osvi) == 0) {        return false;    }    DWORD  dwReturnval;    if(osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) {        /*        .常量 SE_BACKUP_PRIVILEGE, "17", 公開        .常量 SE_RESTORE_PRIVILEGE, "18", 公開        .常量 SE_SHUTDOWN_PRIVILEGE, "19", 公開        .常量 SE_DEBUG_PRIVILEGE, "20", 公開        */        RtlAdjustPrivilege(19, 1, 0, &dwReturnval);    }    //強制關機, 不向進程發送WM_QUERYENDSESSION訊息    //ExitWindowsEx(EWX_FORCE, 0); //退出使用者    ZwShutdownSystem(2);  //直接黑屏    return 0;}

 

Windows 瞬間關機代碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.