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

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.¢% 閱讀(324) 評論(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>
            亚洲美女免费视频| 亚洲黄色成人网| 亚洲婷婷综合色高清在线| 你懂的视频一区二区| 亚洲美女精品成人在线视频| 亚洲美女av黄| 国产精品日韩久久久| 久久aⅴ国产紧身牛仔裤| 久久精品国产精品亚洲| 91久久精品网| 亚洲午夜精品一区二区| 国产在线精品二区| 亚洲国产精品悠悠久久琪琪| 欧美日韩日日夜夜| 久久精品国产亚洲一区二区| 久久久夜夜夜| 亚洲视频中文| 久久久久久久久蜜桃| 夜久久久久久| 欧美在线短视频| 亚洲精品一区二区在线观看| 亚洲午夜激情在线| 在线精品视频一区二区| 一区二区免费在线观看| 红桃视频欧美| 亚洲视频axxx| 亚洲精品偷拍| 久久久久久一区二区三区| 欧美午夜电影完整版| 亚洲欧美国产制服动漫| 国产精品午夜在线| 久久精品2019中文字幕| 欧美韩国日本一区| 久久国产精品72免费观看| 欧美国产在线观看| 久久久久99| 欧美日韩视频在线第一区| 久久久久这里只有精品| 欧美日韩在线不卡一区| 欧美成人日韩| 精品不卡在线| 亚洲欧美成aⅴ人在线观看| 亚洲精品网站在线播放gif| 欧美一级久久久| 亚洲欧美日韩国产综合| 欧美高清视频在线| 麻豆精品网站| 国产亚洲欧美日韩一区二区| 一本色道久久88综合亚洲精品ⅰ| 亚洲激情第一页| 久久久高清一区二区三区| 性色av一区二区三区红粉影视| 欧美精品一区二区在线观看| 欧美aⅴ99久久黑人专区| 国产亚洲欧美一区在线观看| 亚洲一级二级| 性亚洲最疯狂xxxx高清| 欧美视频不卡| 一区二区av| 亚洲一区二区黄色| 欧美日韩精选| 一卡二卡3卡四卡高清精品视频| 日韩视频免费观看| 欧美欧美天天天天操| 亚洲欧洲久久| 一本久道久久综合狠狠爱| 欧美日韩国产黄| 亚洲美女诱惑| 亚洲一区二区三区久久| 欧美性大战久久久久久久蜜臀| 日韩视频永久免费| 亚洲欧美另类在线| 国产日本欧美视频| 欧美专区在线播放| 欧美成人一区二区| 洋洋av久久久久久久一区| 欧美体内she精视频| 亚洲男人的天堂在线| 久久久久欧美| 91久久香蕉国产日韩欧美9色| 欧美国产日韩xxxxx| 一区二区高清在线| 久久久久成人精品免费播放动漫| 狠狠爱成人网| 欧美高清自拍一区| 亚洲香蕉伊综合在人在线视看| 午夜亚洲影视| 一区在线观看| 欧美日本簧片| 欧美一级播放| 亚洲高清一区二| 午夜电影亚洲| 在线欧美一区| 国产精品美女999| 久久久美女艺术照精彩视频福利播放| 亚洲大胆av| 亚洲综合色噜噜狠狠| 欧美一区二区精品| 亚洲国产mv| 国产精品久久综合| 麻豆精品在线观看| 中文有码久久| 欧美国产精品va在线观看| 亚洲一区二区高清| 亚洲国产日韩一区| 国产精品一级二级三级| 蜜臀a∨国产成人精品| 亚洲一区精品视频| 亚洲国产人成综合网站| 久久精品夜色噜噜亚洲a∨| 日韩视频免费观看| 韩国av一区二区三区在线观看| 欧美日韩三级电影在线| 久久夜精品va视频免费观看| 亚洲午夜精品国产| 亚洲精品国产视频| 欧美a级片网站| 久久精品亚洲精品国产欧美kt∨| 夜色激情一区二区| 最新国产精品拍自在线播放| 国产欧美日韩三级| 国产精品第2页| 欧美精品久久久久久久久久| 久久久国产91| 久久激五月天综合精品| 亚洲影视中文字幕| 中日韩男男gay无套| 亚洲精品在线观看免费| 欧美激情国产日韩| 欧美mv日韩mv国产网站| 久久婷婷综合激情| 久久青草欧美一区二区三区| 欧美在线免费看| 亚洲欧美中文字幕| 亚洲在线观看免费| 亚洲视频精选在线| 亚洲视频在线免费观看| 一个色综合av| 中日韩视频在线观看| 99成人免费视频| 99国内精品久久久久久久软件| 亚洲精品一区二区三区在线观看| 亚洲国产精品久久久久秋霞蜜臀| 在线精品视频一区二区三四| 一区在线电影| 亚洲人在线视频| 亚洲精品久久久蜜桃| 亚洲美女色禁图| 一区二区久久| 亚洲女优在线| 欧美一区二区日韩| 久久久999| 免费永久网站黄欧美| 欧美成人一区二区| 亚洲黄色在线视频| 正在播放欧美一区| 欧美亚洲一区二区三区| 久久精品视频在线| 蜜臀久久99精品久久久画质超高清| 免费成人网www| 欧美日韩一区二区三区免费 | 国产亚洲精品成人av久久ww| 国产亚洲美州欧州综合国| 国内自拍亚洲| 亚洲日本视频| 亚洲综合激情| 久久天堂国产精品| 亚洲国产日韩欧美一区二区三区| 亚洲精品一区中文| 午夜精品亚洲| 欧美xxx成人| 国产精品一区二区在线观看| 悠悠资源网亚洲青| 一区二区欧美日韩| 久久精品日产第一区二区| 欧美国产一区二区三区激情无套| 亚洲精选视频在线| 欧美一区二区日韩| 欧美日韩极品在线观看一区| 国产精品一区在线观看| 亚洲韩国精品一区| 欧美一区在线视频| 亚洲国产婷婷香蕉久久久久久| 国产精品99久久久久久www| 久久九九精品| 国产精品久久久| 亚洲韩日在线| 久久精品国产亚洲一区二区三区 | 亚洲精品乱码久久久久久黑人 | 中日韩男男gay无套| 久久综合久久久久88| 国产精品久久久久久久一区探花| 亚洲成色777777女色窝| 欧美亚洲免费在线| 亚洲精品乱码久久久久久| 久久露脸国产精品| 国产欧美日韩一区二区三区在线观看| 亚洲精品黄网在线观看| 久久亚洲色图| 亚洲免费视频成人|