在DELPHI 中如何用 API 將WIN2K 關機? ( 积分: 50 )

  • 主题发起人 主题发起人 hxt33
  • 开始时间 开始时间
H

hxt33

Unregistered / Unconfirmed
GUEST, unregistred user!
各位高手,我裝的是WIN2K系統,因為其它原因導至不能關機,重啟等等都不能用了,我又不想重裝系統,我想用DELHPI編一個程序來關機,可是找不到那方面的資料,請大家幫幫盡快吧!!謝謝!!
 
各位高手,我裝的是WIN2K系統,因為其它原因導至不能關機,重啟等等都不能用了,我又不想重裝系統,我想用DELHPI編一個程序來關機,可是找不到那方面的資料,請大家幫幫盡快吧!!謝謝!!
 
procedure MyShutDown;<br> &nbsp;procedure AdjustToken;<br> &nbsp;var<br> &nbsp; &nbsp;hdlProcessHandle : Cardinal;<br> &nbsp; &nbsp;hdlTokenHandle : Cardinal;<br> &nbsp; &nbsp;tmpLuid : Int64;<br> &nbsp; &nbsp;tkpPrivilegeCount : Int64;<br> &nbsp; &nbsp;tkp : TOKEN_PRIVILEGES;<br> &nbsp; &nbsp;tkpNewButIgnored : TOKEN_PRIVILEGES;<br> &nbsp; &nbsp;lBufferNeeded : Cardinal;<br> &nbsp; &nbsp;Privilege : array[0..0] of _LUID_AND_ATTRIBUTES;<br> &nbsp;begin<br> &nbsp; &nbsp;hdlProcessHandle := GetCurrentProcess;<br> &nbsp; &nbsp;OpenProcessToken(hdlProcessHandle,(TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY),hdlTokenHandle);<br> &nbsp; &nbsp;// Get the LUID for shutdown privilege.<br> &nbsp; &nbsp;LookupPrivilegeValue('', 'SeShutdownPrivilege', tmpLuid);<br> &nbsp; &nbsp;Privilege[0].Luid := tmpLuid;<br> &nbsp; &nbsp;Privilege[0].Attributes := SE_PRIVILEGE_ENABLED;<br> &nbsp; &nbsp;tkp.PrivilegeCount := 1; // One privilege to set<br> &nbsp; &nbsp;tkp.Privileges[0] := Privilege[0];<br> &nbsp; &nbsp;// Enable the shutdown privilege in the access token of this<br> &nbsp; &nbsp;// process.<br> &nbsp; &nbsp;AdjustTokenPrivileges(hdlTokenHandle, False, tkp, Sizeof(tkpNewButIgnored), tkpNewButIgnored, lBufferNeeded);<br> &nbsp;end;<br>var<br> &nbsp;hProcess,hAccessToken:THandle;<br> &nbsp;LUID_AND_ATTRIBUTES:TLUIDAndAttributes;<br> &nbsp;TOKEN_PRIVILEGES: TTokenPrivileges;<br> &nbsp;BufferIsNull:DWORD;<br>Const<br> &nbsp;SE_SHUTDOWN_NAME='SeShutdownPrivilege';<br>begin<br> &nbsp;hProcess:=GetCurrentProcess();<br> &nbsp;OpenProcessToken(hprocess,TOKEN_ADJUST_PRIVILEGES+TOKEN_QUERY,hAccessToken);<br> &nbsp;LookupPrivilegeValue(Nil,SE_SHUTDOWN_NAME,LUID_AND_ATTRIBUTES.Luid);<br> &nbsp;LUID_AND_ATTRIBUTES.Attributes:=SE_PRIVILEGE_ENABLED;<br> &nbsp;TOKEN_PRIVILEGES.PrivilegeCount:=1;<br> &nbsp;TOKEN_PRIVILEGES.Privileges[0]:=LUID_AND_ATTRIBUTES;<br> &nbsp;BufferIsNull:=0;<br> &nbsp;AdjustTokenPrivileges(hAccessToken,False,TOKEN_PRIVILEGES,sizeof(TOKEN_PRIVILEGES),Nil,BufferIsNull);<br> &nbsp;ExitWindowsEX(1, EWX_SHUTDOWN);<br>end;
 
xianguo ,你的代碼我試過了,是可能關機!可能關機的時候會顯示“可以安全關機...”的字樣,還要按power鍵關機,這和我直接按power鍵關機沒有多大分別!這些應該和電腦配置沒有關系吧?你能不能再幫我改一改呀?謝謝!!
 
我的系統是WIN2K pro 繁體版的
 
AdjustToken........<br>ExitWindowsEx(EWX_POWEROFF or EWX_FORCE,0);
 
多人接受答案了。
 
后退
顶部