如何在win2000的小用户下,实现软件关机(50分)

  • 主题发起人 主题发起人 tg
  • 开始时间 开始时间
T

tg

Unregistered / Unconfirmed
GUEST, unregistred user!
小用户,属于Users组,由于本地安全策略没有写注册表权限,没有修改硬盘文件权限,很多程序没有执行权限....<br>前面人抄的什么获得关机权限的程序没用,请高手指点.
 
先取得权限,再关机<br>这段能在windows 2000下关机,记不得时谁写的了(不是我)<br>//------------关机-------------<br>procedure ShutDown();<br>const<br>&nbsp; SE_SHUTDOWN_NAME='SeShutdownPrivilege'; &nbsp;var<br>&nbsp; hToken:THandle;<br>&nbsp; tkp:TTokenPrivileges;<br>&nbsp; tkpo:TTokenPrivileges;<br>&nbsp; zero:DWORD;<br>begin<br>&nbsp; &nbsp; &nbsp; &nbsp;zero := 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; if not OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MessageBox( 0, 'Exit Error', 'OpenProcessToken() Failed', MB_OK );<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Exit;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end; // if not OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken)<br>&nbsp; &nbsp; &nbsp; &nbsp; if not OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MessageBox( 0, 'Exit Error', 'OpenProcessToken() Failed', MB_OK );<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Exit;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end; // if not OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken)<br><br><br>&nbsp; &nbsp; &nbsp; &nbsp; // SE_SHUTDOWN_NAME<br>&nbsp; &nbsp; &nbsp; &nbsp; if not LookupPrivilegeValue( nil, 'SeShutdownPrivilege' , tkp.Privileges[ 0 ].Luid ) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MessageBox( 0, 'Exit Error', 'LookupPrivilegeValue() Failed', MB_OK );<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Exit;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end; // if not LookupPrivilegeValue( nil, 'SeShutdownPrivilege' , tkp.Privileges[0].Luid )<br>&nbsp; &nbsp; &nbsp; &nbsp; tkp.PrivilegeCount := 1;<br>&nbsp; &nbsp; &nbsp; &nbsp; tkp.Privileges[ 0 ].Attributes := SE_PRIVILEGE_ENABLED;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; AdjustTokenPrivileges( hToken, False, tkp, SizeOf( TTokenPrivileges ), tkpo, zero );<br>&nbsp; &nbsp; &nbsp; &nbsp; if Boolean( GetLastError() ) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MessageBox( 0, 'Exit Error', 'AdjustTokenPrivileges() Failed', MB_OK );<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Exit;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end // if Boolean( GetLastError() )<br>&nbsp; &nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ExitWindowsEx( EWX_FORCE or EWX_SHUTDOWN, 0 );//EWX_SHUTDOWN<br>&nbsp; &nbsp; &nbsp;
 
接受答案了.
 
后退
顶部