VC 瞬间关机(使用RtlAdjustPrivilege和ZwShutdownSystem)
#include <windows.h>const unsigned int SE_SHUTDOWN_PRIVILEGE = 0x13;
int main()
{
HMODULE hDll = ::LoadLibrary("ntdll.dll");
typedef int (* type_RtlAdjustPrivilege)(int, bool, bool, int*);
typedef int (* type_ZwShutdownSystem)(int);
type_RtlAdjustPrivilege RtlAdjustPrivilege = (type_RtlAdjustPrivilege)GetProcAddress(hDll, "RtlAdjustPrivilege");
type_ZwShutdownSystem ZwShutdownSystem = (type_ZwShutdownSystem)GetProcAddress(hDll, "ZwShutdownSystem");
int nEn = 0;
int nResult = RtlAdjustPrivilege(SE_SHUTDOWN_PRIVILEGE, true, true, &nEn);
if(nResult == 0x0c000007c)
{
nResult = RtlAdjustPrivilege(SE_SHUTDOWN_PRIVILEGE, true, false, &nEn);
}
nResult = ZwShutdownSystem(2);
FreeLibrary(hDll);
return 0;
}
后面的freelibrary多余。。。 本帖最后由 lxl1638 于 2011-2-27 19:45 编辑
要看ZwShutdownSystem的返回值,是否FreeLibrary
这样写是不错的,ZwShutdownSystem执行成功,系统就关闭,FreeLibrary就不被执行;
ZwShutdownSystem执行不成功,系统不能关闭,FreeLibrary就要执行。 本帖最后由 Murray 于 2011-5-12 23:07 编辑
比ExitWindows方便多了。
.代码量要少很多阿代码copy下了 呵呵,写的可以,哈哈 请问楼主 支持win7吗
页:
[1]