WIN 2K 的关机API函数是什么?(100分)

  • 主题发起人 主题发起人 itfly
  • 开始时间 开始时间
I

itfly

Unregistered / Unconfirmed
GUEST, unregistred user!
WIN 2K 的关机API函数是什么?
 
2000下没有直接可用的api函数可关机<br>win98下可用ExitWindowsEx<br>
 
void RebootSystem()<br>{<br> HANDLE hToken; <br> TOKEN_PRIVILEGES tkp; <br>&nbsp; // Get a token for this process. <br> OpenProcessToken(GetCurrentProcess(), <br> TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &amp;hToken); <br>&nbsp; // Get the LUID for the shutdown privilege. <br> LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, <br> &amp;tkp.Privileges[0].Luid); <br> tkp.PrivilegeCount = 1; &nbsp;// one privilege to set <br> tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; <br> // Get the shutdown privilege for this process. <br> AdjustTokenPrivileges(hToken, FALSE, &amp;tkp, 0, <br> (PTOKEN_PRIVILEGES)NULL, 0); <br>&nbsp;// Cannot test the return value of AdjustTokenPrivileges. <br> // Shut down the system and force all applications to close. <br> <br> //ExitWindowsEx(EWX_REBOOT, 0); <br> //Sleep(3000);<br> //ExitWindowsEx(EWX_REBOOT | EWX_FORCE, 0); <br> InitiateSystemShutdown(NULL,NULL,0,TRUE,FALSE);<br> AbortSystemShutdown(NULL);<br> <br>}<br><br>给你个C++的关机,API,都是,WIN2K中关机需要先取得权限
 
//可用于WIN2000和WINXP(别忘了给分啊![:)]<br>Function MyExitWindows(RebootParam:Longword):Boolean;<br>var<br>TTokenHd:THandle;<br>TTokenPvg:TTokenPrivileges;<br>cbtpPrevious:DWORD;<br>rTTokenPvg:TTokenPrivileges;<br>pcbtpPreviousRequired:DWORD;<br>tpResult:Boolean;<br>const<br>SE_SHUTDOWN_NAME='SeShutdownPrivilege';<br>begin<br>if Win32Platform=VER_PLATFORM_WIN32_NT then<br>begin<br>tpResult:=OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES OR TOKEN_QUERY,TTokenHd);<br>if tpResult then<br>begin<br>tpResult:=LookupPrivilegeValue(nil,SE_SHUTDOWN_NAME,TTokenPvg.Privileges[0].Luid);<br>TTokenPvg.PrivilegeCount:=1;<br>TTokenPvg.Privileges[0].Attributes :=SE_PRIVILEGE_ENABLED;<br>cbtpPrevious:=SizeOf(rTTokenPvg);<br>pcbtpPreviousRequired:=0;<br>if tpResult then<br>Windows.AdjustTokenPrivileges(TTokenHd,False,TTokenPvg,cbtpPrevious,rTTokenPvg,pcbtpPreviousRequired);<br>end;<br>end;<br>Result:=ExitWindowsEx(RebootParam,0);<br>end;<br><br>procedure TForm1.BtnShutDownClick(Sender: TObject);<br>begin<br>//关机<br>MyExitWindows(EWX_SHUTDOWN);<br>end;<br><br>procedure TForm1.BtnLogOffClick(Sender: TObject);<br>begin<br>//注销<br>&nbsp; &nbsp; &nbsp;ExitWindowsex(EWX_LOGOFF,1);<br>end;<br><br>procedure TForm1.BtnRebootClick(Sender: TObject);<br>begin<br>//重新启动计算机<br>&nbsp; &nbsp; &nbsp;MyExitWindows(EWX_REBOOT);<br>end;
 
不能关闭电源啊!?!
 
我用的很正常,请检查你WINDOWS的电源管理设置
 
控制面板-》电源管理-》高级电源管理-》启动高级管理支持 应该选中<br>然后用LGS兄的代码应该没问题!^_^
 
ExitWindowsEx()和ExitWindows(),
 
pcspace我的电脑没有高级电源管理。怎么办?!为什么系统自己可以切断电源,而程序不行呢?!
 
我这个绝对可以关闭电源 关机前可千万别忘了一件事——给我加分:)<br>procedure ShutDown(bShut:Boolean);<br>const<br>&nbsp; SE_SHUTDOWN_NAME = 'SeShutdownPrivilege'; &nbsp; // Borland forgot this declaration<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>&nbsp; zero &nbsp; &nbsp; &nbsp; &nbsp; : DWORD;<br>&nbsp; VersionInfo &nbsp;: TOSVERSIONINFO;<br>begin<br>&nbsp; versioninfo.dwOSVersionInfoSize :=SizeOf( TOSVersionInfo );<br>&nbsp; GetVersionEx(versioninfo);<br>&nbsp; if versioninfo.dwPlatformId=VER_PLATFORM_WIN32_NT then<br>&nbsp; &nbsp; 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;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; // SE_SHUTDOWN_NAME<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>&nbsp; &nbsp; &nbsp;end // if Windows NT<br>&nbsp; else // just shut the machine down<br>&nbsp; &nbsp; &nbsp; &nbsp; ExitWindowsEx(EWX_SHUTDOWN or EWX_FORCE, 0 )<br>end;
 
谢谢 POWERXJQ,CJSAM ,LGS等朋友,请接分!
 
后退
顶部