- 在线时间
- 1957 小时
- 最后登录
- 2024-6-29
- 注册时间
- 2004-4-26
- 听众数
- 49
- 收听数
- 0
- 能力
- 60 分
- 体力
- 40960 点
- 威望
- 6 点
- 阅读权限
- 255
- 积分
- 23863
- 相册
- 0
- 日志
- 0
- 记录
- 0
- 帖子
- 20501
- 主题
- 18182
- 精华
- 5
- 分享
- 0
- 好友
- 140
TA的每日心情 | 奋斗 2024-6-23 05:14 |
|---|
签到天数: 1043 天 [LV.10]以坛为家III
 群组: 万里江山 群组: sas讨论小组 群组: 长盛证券理财有限公司 群组: C 语言讨论组 群组: Matlab讨论组 |
< >bool closecomputer(int kind)9 U3 O! f3 y5 \6 t7 R- h% [% A4 T
{( p. U. I, Y: m9 a; g2 w) W
HANDLE hToken;
0 l' w+ J: y8 l7 R) C TOKEN_PRIVILEGES tkp; </P>
* ~ c5 ]" O, s4 R7 K# Z) s< > // Get a token for this process.
8 S5 m. G) w: A$ b8 u5 j if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))9 y& U% J) ^& G2 F: k$ F' l
{& c0 y. V# s/ B
return false;7 i0 Q4 F& f& W$ m5 d, f
}</P>; I3 t- U( N% ?7 ~ h4 Y
< > // Get the LUID for the shutdown privilege.$ ]# H- f: ^+ a) U6 q+ B. j
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid); </P>
( L s" S* z J) f/ b9 d2 v. P< > tkp.PrivilegeCount = 1; // one privilege to set
& A7 M$ E; a* b, C2 w; z9 `. v tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;</P> \* a- S5 w& I$ \
< > // Get the shutdown privilege for this process.
, O( s y4 G" Y1 [7 ]/ W( w* q AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0);</P>
; A4 A3 _8 |9 i. Z< > if (GetLastError() != ERROR_SUCCESS)' B' V% Z+ K8 D
{
+ e# \. j' J* J/ T4 W& B return false;
) L; v: e: \$ T6 `) i3 N }: y$ ~" l3 |% d6 j B
switch(kind)
2 l, _! H; l" p8 N$ D7 d' c( Y {case 1: ExitWindowsEx(EWX_FORCE|EWX_REBOOT,0); break; //重启& J! _8 I P- U- n: X) U% c
case 2: ExitWindowsEx(EWX_FORCE|EWX_SHUTDOWN|EWX_POWEROFF,0); break; //关机" Y0 ^0 h* d& l- E
case 3: ExitWindowsEx(EWX_FORCE|EWX_LOGOFF,0); break; //注销7 ~1 p- _3 l8 ^" w# m
case 4: SetSystemPowerState(false, true); break; //休眠
0 @. M5 N1 L8 ]% {9 c1 X case 5: SetSystemPowerState(true, true); break; //待机
m4 B/ X* U+ l4 n# a. h5 }: ?3 D default: break;8 ~% a5 x/ e4 U7 ] K+ {; ]
} n/ G/ g9 c# X, s9 N- N
return true;</P>% `( Y6 x$ n, B9 e) O) v
< >}</P> |
zan
|