win2K下exitwindowex调用的问题?(100分)

  • 主题发起人 主题发起人 对酒当歌
  • 开始时间 开始时间

对酒当歌

Unregistered / Unconfirmed
GUEST, unregistred user!
用exitwindowex关闭计算机,win9x下好使,但在win2k下不好使,查msdn说需要调用<br>adjusttokenprivilage(好像这么写,有可能不太准确),我在delphi5中调用此函数失败<br>(当然有其他函数配合,就不写了),请高手提供win2k下关机的全部代码?
 
转贴,我的程序中这是这样调用的.<br>function SetPrivilege(sPrivilegeName: string; bEnabled: boolean ): boolean;<br>var<br>&nbsp; TPPrev,TP : TTokenPrivileges;<br>&nbsp; Token : THandle;<br>&nbsp; dwRetLen : DWord;<br>begin<br>&nbsp; Result := False;<br><br>&nbsp; OpenProcessToken(<br>&nbsp; &nbsp; &nbsp;GetCurrentProcess, //handle to process<br>&nbsp; &nbsp; &nbsp;TOKEN_ADJUST_PRIVILEGES //Required to change the privileges specified in an access token.<br>&nbsp; &nbsp; &nbsp;or TOKEN_QUERY, //Required to query the contents of an access token.<br>&nbsp; &nbsp; &nbsp;Token);<br><br>&nbsp; TP.PrivilegeCount := 1;<br>&nbsp; //retrieves the locally unique identifier (LUID) used on a specified system to<br>&nbsp; //locally represent the specified privilege name.<br>&nbsp; if( LookupPrivilegeValue(<br>&nbsp; &nbsp; &nbsp; Nil, //attempts to find the privilege name on the local system.<br>&nbsp; &nbsp; &nbsp; PChar( sPrivilegeName ), // address of string specifying the privilege<br>&nbsp; &nbsp; &nbsp; TP.Privileges[ 0 ].LUID ) // address of locally unique identifier<br>&nbsp; &nbsp; &nbsp; )then<br>&nbsp; begin<br>&nbsp; &nbsp; if( bEnabled )then //Give this privileges<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp;TP.Privileges[ 0 ].Attributes := SE_PRIVILEGE_ENABLED;<br>&nbsp; &nbsp; end<br>&nbsp; &nbsp; else begin //NOT Give this privileges<br>&nbsp; &nbsp; &nbsp; &nbsp;TP.Privileges[ 0 ].Attributes := 0;<br>&nbsp; &nbsp; end;<br><br>&nbsp; &nbsp; dwRetLen := 0;<br>&nbsp; &nbsp; //enables or disables privileges in the specified access token.<br>&nbsp; &nbsp; Result := AdjustTokenPrivileges(<br>&nbsp; &nbsp; &nbsp; &nbsp; Token, // handle to token that contains privileges<br>&nbsp; &nbsp; &nbsp; &nbsp; False, //modifies privileges<br>&nbsp; &nbsp; &nbsp; &nbsp; TP, // pointer to new privilege information<br>&nbsp; &nbsp; &nbsp; &nbsp; SizeOf( TPPrev ), // size, in bytes, of the TPPrev buffer<br>&nbsp; &nbsp; &nbsp; &nbsp; TPPrev, // receives original state of changed privileges<br>&nbsp; &nbsp; &nbsp; &nbsp; dwRetLen // receives required size of the TPPrev buffer<br>&nbsp; &nbsp; &nbsp; &nbsp; );<br>&nbsp; end;<br>&nbsp; CloseHandle( Token );<br>end;<br><br>function WinExitInNT( iFlags : integer ) : boolean;<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; &nbsp;Result := False;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; SetPrivilege('SeShutdownPrivilege', False )<br>&nbsp; end<br>&nbsp; else begin<br>&nbsp; &nbsp; &nbsp; &nbsp;// handle errors...<br>&nbsp; &nbsp; &nbsp; &nbsp;Result := False;<br>&nbsp; end;<br>end;<br><br>//调用.<br>&nbsp; &nbsp; &nbsp;WinExitInNT(EWX_SHUTDOWN+EWX_POWEROFF+EWX_FORCE);
 
谢谢zhangkan ,好像对我有些启发,我回去试试,好使就送分<br>
 
接受答案了.
 
后退
顶部