一个简单问题!(50分)

  • 主题发起人 主题发起人 xiaoshou
  • 开始时间 开始时间
X

xiaoshou

Unregistered / Unconfirmed
GUEST, unregistred user!
在window2000 sever中我用<br>ExitWindowsEx(EWX_FORCE+Ewx_SHUTDOWN,0);关闭计算机(不行为什么?);<br>ExitWindowsEX(EWX_FORCE+EWX_REBOOT,0);重起计算机(也不行?)<br>只有<br>ExitWindowsEx(EWX_FORCE+EWX_LOGOFF,0);有效!<br>为什么会出现这样的情况!是不是我window2000 sever 重起和关闭文件已经破坏?<br>如何解决?:)
 
试试下面这个吧,绝对没问题!<br>procedure ShutDown(bShut:Boolean);<br>const<br>&nbsp; SE_SHUTDOWN_NAME = 'SeShutdownPrivilege'; &nbsp; <br>var<br>&nbsp; hToken &nbsp; &nbsp; &nbsp; : THandle;<br>&nbsp; tkp &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: TTokenPrivileges;<br>&nbsp; tkpo &nbsp; &nbsp; &nbsp; &nbsp; : TTokenPrivileges;<br>begin<br>&nbsp; &nbsp; &nbsp; &nbsp;if not OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MessageBox( 0, 'Error', 'OpenProcessToken() Failed', MB_OK );<br>&nbsp; &nbsp; &nbsp; &nbsp;if not OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MessageBox( 0, 'Error', 'OpenProcessToken() Failed', MB_OK );<br>&nbsp; &nbsp; &nbsp; &nbsp;if not LookupPrivilegeValue( nil, SE_SHUTDOWN_NAME , tkp.Privileges[ 0 ].Luid ) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MessageBox( 0, 'Error', 'LookupPrivilegeValue() Failed', MB_OK );<br>&nbsp; &nbsp; &nbsp; &nbsp;tkp.PrivilegeCount := 1;<br>&nbsp; &nbsp; &nbsp; &nbsp;tkp.Privileges[ 0 ].Attributes := SE_PRIVILEGE_ENABLED;<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;MessageBox( 0, 'Error', 'AdjustTokenPrivileges() Failed', MB_OK )<br>&nbsp; &nbsp; &nbsp; &nbsp;else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ExitWindowsEx(EWX_POWEROFF or EWX_FORCE,0);<br>end;
 
powerXJQ你能不能和我讲一下OpenProcessToken,TTokenPrivileges,LookupPrivilegeValue的含义呀!我用delphi7帮助找不到:)我很苯谢谢!<br>zero是不是定义为:word;<br>你上面的是关闭程序,难道我的重起按纽还要在抄一遍在把<br>else改为exitwindosex(ewx_reboot,0)这样的很罗嗦哦:)<br>
 
win2000关机需要获得一定权限,就要用到AdjustTokenPrivileges等api函数获得,<br>获得权限后才能关机或重启,可以在MSDN里找到。<br>你可以把关机和重启写在一个函数里,靠参数确定调用哪个。
 
明白!:)现在我把分给你:)
 
后退
顶部