WINDOWS2000中如何关机?(50分)

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

luckhacker

Unregistered / Unconfirmed
GUEST, unregistred user!
请问在WINDOWS2000中如何利用WINDOS API函数关闭计算机?
 
function SetPrivilege(aPrivilegeName : string;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; aEnabled : boolean ): boolean; <br>var <br>&nbsp; TPPrev, <br>&nbsp; TP &nbsp; &nbsp; &nbsp; &nbsp; : TTokenPrivileges; <br>&nbsp; Token &nbsp; &nbsp; &nbsp;: THandle;<br>&nbsp; dwRetLen &nbsp; : DWord; <br>begin <br>&nbsp; Result := False; <br>&nbsp; OpenProcessToken(GetCurrentProcess,TOKEN_ADJUST_PRIVILEGES<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;or TOKEN_QUERY, Token );<br><br>&nbsp; TP.PrivilegeCount := 1; <br>&nbsp; if( LookupPrivilegeValue(nil, PChar( aPrivilegeName ), <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TP.Privileges[ 0 ].LUID ) ) then<br>&nbsp; begin <br>&nbsp; &nbsp; if( aEnabled )then<br>&nbsp; &nbsp; &nbsp; TP.Privileges[0].Attributes:= SE_PRIVILEGE_ENABLED <br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; TP.Privileges[0].Attributes:= 0; <br><br>&nbsp; &nbsp; dwRetLen := 0;<br>&nbsp; &nbsp; Result := AdjustTokenPrivileges(Token,False,TP, <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SizeOf( TPPrev ), <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TPPrev,dwRetLen ); <br>&nbsp; end;<br><br>&nbsp; CloseHandle( Token ); <br>end; <br><br><br>function WinExit( iFlags : integer ) : boolean;<br>// &nbsp; possible Flags: <br>// &nbsp; EWX_LOGOFF<br>// &nbsp; EWX_REBOOT<br>// &nbsp; EWX_SHUTDOWN<br>begin<br>&nbsp; Result := True;<br>&nbsp; if( SetPrivilege( 'SeShutdownPrivilege', true ) ) then<br>&nbsp; begin<br>&nbsp; &nbsp; if( not ExitWindowsEx( iFlags, 0 ) )then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Result := False;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; SetPrivilege( 'SeShutdownPrivilege', False )<br>&nbsp; end<br>&nbsp; else<br>&nbsp; begin<br>&nbsp; &nbsp; Result := False;<br>&nbsp; end;<br>end;<br>
 
我要一份:)
 
不会有这么繁吧?
 
同样XK的
 
Const<br>&nbsp; SE_SHUTDOWN_NAME = 'SeShutdownPrivilege';<br>Var<br>&nbsp; hToken : THandle;<br>&nbsp; Tkp : TTokenPrivileges;<br>&nbsp; Tkpo : TTokenPrivileges;<br>&nbsp; Zero : DWORD;<br>begin<br>&nbsp; Zero :=0;<br>&nbsp; OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken);<br>&nbsp; LookupPrivilegeValue( nil, 'SeShutdownPrivilege' , tkp.Privileges[ 0 ].Luid );<br>&nbsp; Tkp.PrivilegeCount :=1;<br>&nbsp; Tkp.Privileges[ 0 ].Attributes := SE_PRIVILEGE_ENABLED;<br>&nbsp; AdjustTokenPrivileges(hToken, False, Tkp, SizeOf( TTokenPrivileges ), Tkpo, Zero );<br>&nbsp; ExitWindowsEx(EWX_SHUTDOWN Or EWX_FORCE,0);<br>end;
 
多人接受答案了。
 
后退
顶部