青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

S.l.e!ep.¢%

像打了激速一樣,以四倍的速度運轉,開心的工作
簡單、開放、平等的公司文化;尊重個性、自由與個人價值;
posts - 1098, comments - 335, trackbacks - 0, articles - 1
  C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

The Fast Way to ShutDown the computer

Posted on 2009-11-04 22:02 S.l.e!ep.¢% 閱讀(332) 評論(0)  編輯 收藏 引用 所屬分類: RootKit

Demo_Executable

?

Introduction

Sometimes an application just needs to quickly shutdown Windows. Unfortunately, there is no well-documented method to do this, and Microsoft does not support it. In fact, neither do I. However, I am presenting two methods to do so just as a mere idea.

Disclaimer: I am not responsible for any unwanted behavior of this program. If your computer doesn't start up again afterwards, it is not my fault. The program is presented merely as a "proof of concept".

Background

Many of the Nt/Zw functions inside the Windows kernel are documented, but some are not. The NtShutdownSystem function is documented pretty well here at NTInternals. The NtSetSystemPowerState function, however, is not.

At the final stages of the Windows shutdown process, NtShutdownSystem is called. It is responsible for shutting down all drivers, flushing Registry hives and the disc cache, clearing the page file, etc. After doing so, it calls the NtSetSystemPowerState function.

NtSetSystemPowerState then causes all plug-and-play devices to be shut down and the system to be either halted, powered off, or rebooted.

However, calling these two functions without notifying the system first is extremely dangerous, and may cause instability in the system.

Using the code

Both NtShutdownSystem and NtSetSystemPowerState are inside NTDLL.DLL, which is why we have to load it first. We also have to enable the SE_SHUTDOWN_NAME privilege in order to call it:

Collapse Copy Code
OpenProcessToken(GetCurrentProcess(),TOKEN_QUERY|TOKEN_ADJUST_PRIVILEGES, &hToken);
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, NULL, 0);
CloseHandle(hToken); 

hNTDLL = LoadLibrary("NTDLL.DLL");

After doing so, we obtain the functions:

Collapse Copy Code
				typedef DWORD (WINAPI* lpNtShutdownSystem)(SHUTDOWN_ACTION Action);
lpNtShutdownSystem NtShutdownSystem = 
   (lpNtShutdownSystem)GetProcAddress(hNTDLL, "NtShutdownSystem");

typedef DWORD (WINAPI* lpNtSetSystemPowerState)(
IN POWER_ACTION SystemAction,IN SYSTEM_POWER_STATE MinSystemState,IN ULONG Flags);
lpNtSetSystemPowerState NtSetSystemPowerState =
   (lpNtSetSystemPowerState)GetProcAddress(hNTDLL, "NtSetSystemPowerState");

As the typedefs show, NtShutdownSystem requires a SHUTDOWN_ACTION parameter, which is documented here. The three options, ShutdownNoReboot, ShutdownReboot, and ShutdownPowerOff are self-explanatory.

NtSetSystemPowerState is a bit more complicated. Microsoft makes it a bit easier for us by documenting all three parameters. The first two, POWER_ACTION and SYSTEM_POWER_STATE, are documented well. The third, flags, is simply the reason for shutdown, which is also documented here on MSDN.

Calling the actual functions is rather simple:

Collapse Copy Code
				void CEmergency_ShutdownDlg::OnShutdown() 
{
    if (NtShutdownSystem)
    {
        DWORD returnval = NtShutdownSystem(ShutdownPowerOff);
        if (returnval != 0) FormatNtMessage(returnval);
    }
}

void CEmergency_ShutdownDlg::OnPowerdown() 
{
    if (NtSetSystemPowerState)
    {
        DWORD returnval = NtSetSystemPowerState(
            PowerActionShutdownOff,
            PowerSystemShutdown,
            SHTDN_REASON_MAJOR_OTHER | 
                       SHTDN_REASON_MINOR_OTHER | 
                       SHTDN_REASON_FLAG_PLANNED
            );
        if (returnval != 0) FormatNtMessage(returnval);
    }
}

FormatNtMessage is simply a specialized function to display an error, given an NTSTATUS error code. It uses the FormatMessage function.

Points of interest

Only one point of interest: save all un-saved work before executing any one of the functions, or else it'd be rather interesting what happens to them.

History

I probably won't be updating this, unless there is a critical flaw anywhere in the code.

  • v1.0 - March 16, 2009.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

hxhl95


Member
A random 14 year old guy in Vancouver with an avid interest in how Windows works. Started coding a few years ago, beginning with a bit of game design using GDI+ and some Windows programming. Recently moved onto messing with the Windows kernel and hoping to get into algorithm design soon.

http://xkcd.com/424/
Location: Canada Canada

Other popular Win32/64 SDK & OS articles:

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            91久久精品日日躁夜夜躁国产| 99日韩精品| 久久精品国产亚洲一区二区| 亚洲综合不卡| 国产日韩视频| 久久蜜桃精品| 欧美国产精品v| 亚洲在线电影| 欧美伊人久久| 亚洲美女视频网| 在线一区二区视频| 国产一区二区三区自拍| 欧美高清影院| 国产精品成人aaaaa网站| 午夜精品网站| 久久综合狠狠综合久久综青草 | 在线成人h网| 亚洲电影在线观看| 欧美日韩视频在线第一区| 亚洲欧美日韩综合aⅴ视频| 欧美在线视频一区二区| 亚洲国产成人91精品| 99re6这里只有精品视频在线观看| 国产精品久久久久久久一区探花| 久久激情婷婷| 欧美剧在线免费观看网站| 久久高清国产| 欧美劲爆第一页| 欧美中日韩免费视频| 欧美成人综合网站| 久久精品30| 欧美日韩精品欧美日韩精品| 久久精品在这里| 欧美日韩中字| 欧美激情中文字幕乱码免费| 国产精品乱码| 亚洲精品视频一区二区三区| 国产美女诱惑一区二区| 亚洲国产一区二区三区在线播| 国产欧美日韩一区| 91久久国产综合久久91精品网站| 国产精品免费看片| 最新亚洲视频| 激情一区二区三区| 亚洲综合视频网| 一本色道久久加勒比88综合| 久久九九国产| 玖玖精品视频| 国产一区二区三区免费不卡| 亚洲美女黄网| 亚洲黄色免费| 久久综合国产精品| 久久婷婷国产麻豆91天堂| 国产精品hd| 亚洲精品综合| 一本色道久久综合亚洲精品不 | 国产精品福利在线| 欧美激情国产日韩| 一区二区在线视频播放| 亚洲综合大片69999| 亚洲视频在线观看免费| 欧美日本不卡高清| 亚洲精品激情| 国产精品99久久久久久宅男| 欧美激情国产高清| 亚洲国产成人一区| 91久久极品少妇xxxxⅹ软件| 久久综合电影| 欧美黄色日本| 亚洲国产日韩欧美| 免费观看一级特黄欧美大片| 亚洲国产精品一区二区第四页av| 亚洲国产你懂的| 欧美成人有码| 亚洲精品一级| 亚洲欧美电影在线观看| 国产精品一区久久| 欧美一区二区在线免费观看| 蜜臀久久99精品久久久久久9 | 雨宫琴音一区二区在线| 久久成人精品一区二区三区| 久久亚洲春色中文字幕| 在线看片成人| 欧美日韩www| 亚洲午夜精品视频| 久久久7777| 亚洲激情第一页| 国产精品jizz在线观看美国 | 久久综合电影| 亚洲精品视频免费| 午夜精品久久久久久99热| 国产私拍一区| 免费看亚洲片| 亚洲女同精品视频| 免费成人黄色片| 中文国产成人精品| 狠狠综合久久av一区二区老牛| 久久中文在线| 在线午夜精品| 欧美h视频在线| 亚洲影视中文字幕| 影视先锋久久| 国产精品jizz在线观看美国| 久久精品二区亚洲w码| 91久久久久| 久久精品国产一区二区三区| 亚洲精品久久久久久久久久久| 国产精品网站在线播放| 久久这里有精品15一区二区三区| 一本色道久久综合亚洲精品婷婷 | 欧美一区二区三区四区在线观看地址| 你懂的国产精品| 午夜精品一区二区三区电影天堂| 在线播放亚洲| 欧美视频亚洲视频| 美日韩精品免费观看视频| 亚洲欧美日韩国产综合精品二区| 欧美国产日本在线| 久久久精品性| 亚洲专区欧美专区| 亚洲精品免费在线播放| 国产亚洲福利一区| 国产精品videosex极品| 欧美国产欧美综合| 久久精品国产99国产精品澳门| 一区二区欧美亚洲| 亚洲国产一区二区三区a毛片 | 久久久综合网站| 亚洲欧美日韩国产中文在线| 亚洲美女av电影| 亚洲国产精品传媒在线观看| 国产视频观看一区| 国产精品综合视频| 国产精品国产三级国产 | 欧美伊人影院| 亚洲欧美日韩中文播放| 这里只有精品在线播放| 亚洲精选久久| 亚洲精品视频免费观看| 91久久国产综合久久91精品网站| 欧美激情aⅴ一区二区三区| 麻豆精品国产91久久久久久| 久久久久久国产精品mv| 久久精品国产亚洲精品| 久久精品视频一| 久久久久一本一区二区青青蜜月| 欧美一区二区三区男人的天堂 | 韩国一区二区三区在线观看| 国产视频亚洲精品| 国产精品一二三| 国产美女扒开尿口久久久| 国产精品一区在线播放| 国产精品日本一区二区| 国产欧美精品一区二区色综合| 国产欧美精品xxxx另类| 国产婷婷色一区二区三区四区| 国产农村妇女精品一区二区| 国产午夜精品久久| 国内精品亚洲| 亚洲精品视频免费观看| 亚洲美女在线看| 亚洲影视在线播放| 欧美一区二区久久久| 久久影院午夜片一区| 欧美成人a视频| 亚洲精品乱码| 亚洲欧美日韩在线不卡| 久久五月天婷婷| 欧美国产综合视频| 欧美性大战久久久久久久| 国产美女精品| 亚洲精品自在久久| 亚洲一区二区三区免费在线观看 | 在线激情影院一区| 亚洲精品一区二区三区蜜桃久| 一本久久知道综合久久| 欧美中文字幕视频| 欧美国产精品久久| 中文在线不卡视频| 久久这里只精品最新地址| 欧美色欧美亚洲高清在线视频| 国产日韩综合一区二区性色av| 亚洲人成亚洲人成在线观看| 在线午夜精品自拍| 久久久五月天| 亚洲天堂第二页| 免费久久99精品国产自在现线| 国产精品久久久久久久久久尿 | 久久亚洲影院| 日韩小视频在线观看专区| 久久成人资源| 欧美性做爰猛烈叫床潮| 亚洲国产日韩欧美| 久久国产免费| 一二三四社区欧美黄| 欧美99久久| 国产一区二区三区在线观看网站| aa亚洲婷婷| 亚洲高清激情| 久久久久国产一区二区三区四区 |