xp关机函数是什么呀???(20分)

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

li1215

Unregistered / Unconfirmed
GUEST, unregistred user!
各位大侠:<br>&nbsp; &nbsp; 小弟想写一个WINDOWSXP下的定时关机的程序,用2000下的API函数exitwindowsEx,不能实现XP的关机!请问什么函数可以实现,最好把重启、注销、关机参数也说明一下!谢谢!
 
需要獲得關机權限.
 
function GetShutDownPriv : Boolean;<br>const<br>&nbsp; PrivName : PAnsiChar = 'SeShutdownPrivilege';<br>var<br>&nbsp; hToken : THandle;<br>&nbsp; tkp, prev : TTokenPrivileges;<br>&nbsp; retlength : DWORD;<br>begin<br>&nbsp; Result := True;<br>&nbsp; if Win32Platform &lt;&gt; VER_PLATFORM_WIN32_NT then<br>&nbsp; &nbsp; Exit; // just return True if on Win9x since there's no security<br>&nbsp; Result := False; &nbsp;// return False if security token cannot be adjusted on NT<br>&nbsp; if not OpenProcessToken(GetCurrentProcess,<br>&nbsp; &nbsp; TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,<br>&nbsp; &nbsp; hToken) then<br>&nbsp; &nbsp; Exit;<br>&nbsp; if not LookupPrivilegeValue(nil, PrivName, tkp.Privileges[0].Luid) then<br>&nbsp; &nbsp; Exit;<br>&nbsp; prev := tkp;<br>&nbsp; tkp.PrivilegeCount := 1;<br>&nbsp; tkp.Privileges[0].Attributes := 2;<br>&nbsp; AdjustTokenPrivileges(hToken, BOOL(FALSE), tkp, sizeof(prev), prev, retlength);<br>&nbsp; if GetLastError &lt;&gt; ERROR_SUCCESS then<br>&nbsp; &nbsp; Exit;<br>&nbsp; Result := True; // return True if SeShutdownPrivilege accepted<br>End; // GetShutDownPriv<br><br>procedure DoWindowsShutdown;<br>Begin<br>&nbsp; if not GetShutDownPriv then<br>&nbsp; begin<br>&nbsp; &nbsp; MessageBox(0, '不能关闭WIndows : 取消',<br>&nbsp; &nbsp; &nbsp; nil, MB_OK or MB_ICONSTOP or MB_SETFOREGROUND);<br>&nbsp; &nbsp; PostQuitMessage(0);<br>&nbsp; &nbsp; Exit;<br>&nbsp; end;<br>&nbsp; ExitWindowsEx(EWX_POWEROFF, 0); // give user chance to cancel Shutdown<br>end; // DoWindowsShutdown<br>
 
要关闭xp 需要有关机特权。。。<br>&nbsp; &nbsp;先用openprcesstoken打开令牌,,然后才能访问,用LookupPrivilegeValue找出令牌特权<br>的luid,然后再设置特权属性,,用AdjustTokenPrivileges后,,就可以用exitwindowsex关机<br>了..至于这几个API 函数你自己找找看。。。。?<br>也就是说对于这种像win2000和xp这样的有安全的系统,,首先要取得特权... &nbsp;
 
我的运行通过,肯定没问题
 
zzb1984:我已经实现关机!谢谢!马上给你加分!以后请多多指教!也谢谢各位答复的大侠!
 
zzb1984:我已经实现关机!谢谢!马上给你加分!以后请多多指教!也谢谢各位答复的大侠! &nbsp;
 
后退
顶部