找回密码
 加入我们

QQ登录

只需一步,快速开始

搜索
查看: 9445|回复: 5

[开源] VC 瞬间关机(使用RtlAdjustPrivilege和ZwShutdownSystem)

 火.. [复制链接]

1214

主题

352

回帖

11

精华

管理员

菜鸟

积分
93755

贡献奖关注奖人气王精英奖乐于助人勋章

发表于 2011-1-8 15:20:05 | 显示全部楼层 |阅读模式
  1. #include <windows.h>

  2. const unsigned int SE_SHUTDOWN_PRIVILEGE = 0x13;

  3. int main()
  4. {
  5. HMODULE hDll = ::LoadLibrary("ntdll.dll");
  6. typedef int (* type_RtlAdjustPrivilege)(int, bool, bool, int*);
  7. typedef int (* type_ZwShutdownSystem)(int);
  8. type_RtlAdjustPrivilege RtlAdjustPrivilege = (type_RtlAdjustPrivilege)GetProcAddress(hDll, "RtlAdjustPrivilege");
  9. type_ZwShutdownSystem ZwShutdownSystem = (type_ZwShutdownSystem)GetProcAddress(hDll, "ZwShutdownSystem");
  10. int nEn = 0;
  11. int nResult = RtlAdjustPrivilege(SE_SHUTDOWN_PRIVILEGE, true, true, &nEn);
  12. if(nResult == 0x0c000007c)
  13. {
  14. nResult = RtlAdjustPrivilege(SE_SHUTDOWN_PRIVILEGE, true, false, &nEn);
  15. }
  16. nResult = ZwShutdownSystem(2);
  17. FreeLibrary(hDll);
  18. return 0;
  19. }

复制代码
【VB】QQ群:1422505加的请打上VB好友
【易语言】QQ群:9531809  或 177048
【FOXPRO】QQ群:6580324  或 33659603
【C/C++/VC】QQ群:3777552
【NiceBasic】QQ群:3703755

23

主题

117

回帖

1

精华

银牌会员

积分
400
发表于 2011-2-26 20:35:19 | 显示全部楼层
后面的freelibrary多余。。。

7

主题

36

回帖

2

精华

初来乍到

积分
3171
发表于 2011-2-27 01:51:06 | 显示全部楼层
本帖最后由 lxl1638 于 2011-2-27 19:45 编辑

要看ZwShutdownSystem的返回值,是否FreeLibrary
这样写是不错的,ZwShutdownSystem执行成功,系统就关闭,FreeLibrary就不被执行;
ZwShutdownSystem执行不成功,系统不能关闭,FreeLibrary就要执行。

5

主题

68

回帖

2

精华

钻石会员

积分
2738
QQ
发表于 2011-5-12 23:03:53 | 显示全部楼层
本帖最后由 Murray 于 2011-5-12 23:07 编辑

比ExitWindows方便多了。
.代码量要少很多阿  代码copy下了

0

主题

7

回帖

0

精华

初来乍到

积分
9
发表于 2012-2-10 17:00:36 | 显示全部楼层
呵呵,写的可以,哈哈

30

主题

693

回帖

0

精华

钻石会员

积分
2815
发表于 2015-6-12 20:15:27 | 显示全部楼层
请问楼主 支持win7吗
您需要登录后才可以回帖 登录 | 加入我们

本版积分规则

快速回复 返回顶部 返回列表