1、这个API在NT和2000下无效<br>2、控制WINDOWS的开关:如关闭WINDOWS,重新启动WINDOWS等, ExitWindowsEx(UINT uFlags,DWORD dwReserved);<br>首先定义常数<br>const<br>EWX_FORCE=4; //关闭所有程序并以其他用户身份登录<br>EWX_LOGOFF=0; //重新启动计算机并切换到MS-DOS方式<br>EWX_REBOOT=2; //重新启动计算机<br>EWX_SHUTDOWN=1;//关闭计算机<br>运行时给How赋值,让他等于EWX_SHUTDOWN或其他,调用以下语句<br>ExitWindowsEx(How,0);<br>3、介绍一个其他方法,可以在NT、2000下使用的<br>function My_ExitWindows(M_1Reboot_2Power: integer): Boolean; //重启(M:=1).关机(M:=2)<br>var<br>hToken: THANDLE;<br>hProc: THANDLE;<br>mLUID: TLargeInteger;<br>mPriv, mNewPriv: TOKEN_PRIVILEGES;<br>mBufferLength: DWord;<br>begin<br>Result:=false;<br>if not (M_1Reboot_2Power in [1, 2]) then exit;<br>hProc := GetCurrentProcess();<br>OpenProcessToken(hProc, TOKEN_ADJUST_PRIVILEGES + TOKEN_QUERY, hToken);<br>LookupPrivilegeValue('', 'SeShutdownPrivilege', mLUID);<br>mPriv.PrivilegeCount := 1;<br>mPriv.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;<br>mPriv.Privileges[0].Luid := mLUID;<br>AdjustTokenPrivileges(hToken, False, mPriv, (4 + (12 * mPriv.PrivilegeCount)), mNewPriv, mBufferLength);<br>GetLastError;<br>case M_1Reboot_2Power of<br>1: Result := ExitWindowsEx(EWX_FORCE+EWX_REBOOT,0);<br>2: Result := ExitWindowsEx(EWX_FORCE+EWX_POWEROFF, 0);<br>end;<br>end;<br><br>