求满足条件后重起计算机 ( 积分: 100 )

  • 主题发起人 主题发起人 liuzijie
  • 开始时间 开始时间
L

liuzijie

Unregistered / Unconfirmed
GUEST, unregistred user!
程序关闭后自动重起<br>或&nbsp;弹出消息框时重起计算机.<br>本人菜鸟,麻烦大虾们能给的详细些
 
procedure&nbsp;ShutDown;<br>&nbsp;&nbsp;procedure&nbsp;AdjustToken;<br>&nbsp;&nbsp;var<br>&nbsp;&nbsp;&nbsp;&nbsp;hdlProcessHandle&nbsp;:&nbsp;Cardinal;<br>&nbsp;&nbsp;&nbsp;&nbsp;hdlTokenHandle&nbsp;:&nbsp;Cardinal;<br>&nbsp;&nbsp;&nbsp;&nbsp;tmpLuid&nbsp;:&nbsp;Int64;<br>&nbsp;&nbsp;&nbsp;&nbsp;tkp&nbsp;:&nbsp;TOKEN_PRIVILEGES;<br>&nbsp;&nbsp;&nbsp;&nbsp;tkpNewButIgnored&nbsp;:&nbsp;TOKEN_PRIVILEGES;<br>&nbsp;&nbsp;&nbsp;&nbsp;lBufferNeeded&nbsp;:&nbsp;Cardinal;<br>&nbsp;&nbsp;&nbsp;&nbsp;Privilege&nbsp;:&nbsp;array[0..0]&nbsp;of&nbsp;_LUID_AND_ATTRIBUTES;<br>&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;hdlProcessHandle&nbsp;:=&nbsp;GetCurrentProcess;<br>&nbsp;&nbsp;&nbsp;&nbsp;OpenProcessToken(hdlProcessHandle,(TOKEN_ADJUST_PRIVILEGES&nbsp;Or&nbsp;TOKEN_QUERY),hdlTokenHandle);<br>&nbsp;&nbsp;&nbsp;&nbsp;LookupPrivilegeValue('',&nbsp;'SeShutdownPrivilege',&nbsp;tmpLuid);<br>&nbsp;&nbsp;&nbsp;&nbsp;Privilege[0].Luid&nbsp;:=&nbsp;tmpLuid;<br>&nbsp;&nbsp;&nbsp;&nbsp;Privilege[0].Attributes&nbsp;:=&nbsp;SE_PRIVILEGE_ENABLED;<br>&nbsp;&nbsp;&nbsp;&nbsp;tkp.PrivilegeCount&nbsp;:=&nbsp;1;<br>&nbsp;&nbsp;&nbsp;&nbsp;tkp.Privileges[0]&nbsp;:=&nbsp;Privilege[0];<br>&nbsp;&nbsp;&nbsp;&nbsp;AdjustTokenPrivileges(hdlTokenHandle,&nbsp;False,&nbsp;tkp,&nbsp;Sizeof(tkpNewButIgnored),&nbsp;tkpNewButIgnored,&nbsp;lBufferNeeded);<br>&nbsp;&nbsp;end;<br>var<br>&nbsp;&nbsp;hProcess,hAccessToken:THandle;<br>&nbsp;&nbsp;LUID_AND_ATTRIBUTES:TLUIDAndAttributes;<br>&nbsp;&nbsp;TOKEN_PRIVILEGES:&nbsp;TTokenPrivileges;<br>&nbsp;&nbsp;BufferIsNull:DWORD;<br>Const<br>&nbsp;&nbsp;SE_SHUTDOWN_NAME='SeShutdownPrivilege';<br>begin<br>&nbsp;&nbsp;hProcess&nbsp;:=&nbsp;GetCurrentProcess();<br>&nbsp;&nbsp;OpenProcessToken(hprocess,&nbsp;TOKEN_ADJUST_PRIVILEGES+TOKEN_QUERY,&nbsp;hAccessToken);<br>&nbsp;&nbsp;LookupPrivilegeValue(Nil,SE_SHUTDOWN_NAME,LUID_AND_ATTRIBUTES.Luid);<br>&nbsp;&nbsp;LUID_AND_ATTRIBUTES.Attributes:=SE_PRIVILEGE_ENABLED;<br>&nbsp;&nbsp;TOKEN_PRIVILEGES.PrivilegeCount:=1;<br>&nbsp;&nbsp;TOKEN_PRIVILEGES.Privileges[0]:=LUID_AND_ATTRIBUTES;<br>&nbsp;&nbsp;BufferIsNull:=0;<br>&nbsp;&nbsp;AdjustTokenPrivileges(hAccessToken,False,TOKEN_PRIVILEGES,sizeof(TOKEN_PRIVILEGES),Nil,BufferIsNull);<br>&nbsp;&nbsp;ExitWindowsEx(EWX_POWEROFF&nbsp;or&nbsp;EWX_FORCE,&nbsp;0);<br>end;
 
后退
顶部