首先,如果你在win2000的开始菜单中关闭系统,计算机能关闭电源,<br>即主板支持,使用下面函数即可。<br>这是我以前的回答http://www.delphibbs.com/delphibbs/dispq.asp?lid=414648<br>再给你回答一遍<br><br>win2000和nt的关机机制和win98不一样<br>必须调用AdjustTokenPrivileges使se_shutdown_name有效<br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> StdCtrls;<br><br>type<br> TForm1 = class(TForm)<br> Button1: TButton;<br> Memo1: TMemo;<br> Button2: TButton;<br> procedure Button1Click(Sender: TObject);<br> procedure Button2Click(Sender: TObject);<br> private<br> procedure DoShutdown;<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br> logoff: boolean = false;<br> reboot: boolean = false;<br> warn: boolean = false;<br> downQuick: boolean = false;<br> cancelShutdown: boolean = false;<br> powerOff: boolean = false;<br> timeDelay: integer = 0;<br><br><br>implementation<br><br>{$R *.DFM}<br><br>function HasParam(Opt: Char): Boolean;<br>var <br> x: integer; <br>begin <br> result := false; <br> for x := 1 to paramCount do <br> if (paramstr(x) = '-'+opt) or (paramstr(x) = '/'+opt) then result := true; <br>end; <br><br>function GetErrorString: String; <br>var <br> lz: Cardinal; <br> err: array[0..512] of Char; <br>begin <br> lz := GetLastError; <br> FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, nil, lz, 0, @err, 512, nil);<br> result := string(err);<br>end; <br><br>procedure Tform1.DoShutdown;<br>var <br> rl,flgs: Cardinal; <br> hToken: Cardinal; <br> tkp: TOKEN_PRIVILEGES; <br>begin <br> flgs := 0; <br> if downQuick then flgs := flgs or EWX_FORCE; <br> if not reboot then flgs := flgs or EWX_SHUTDOWN; <br> if reboot then flgs := flgs or EWX_REBOOT; <br> if poweroff and (not reboot) then flgs := flgs or EWX_POWEROFF; <br> if logoff then flgs := (flgs and (not (EWX_REBOOT or EWX_SHUTDOWN or EWX_POWEROFF))) or EWX_LOGOFF; <br> if Win32Platform = VER_PLATFORM_WIN32_NT then begin <br> if not OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken) then <br> memo1.lines.add('Cannot open process token. ['+GetErrorString+']')<br> else begin<br> if LookupPrivilegeValue(nil, 'SeShutdownPrivilege', tkp.Privileges[0].Luid) then begin <br> tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;<br> tkp.PrivilegeCount := 1;<br> AdjustTokenPrivileges(hToken, False, tkp, 0, nil, rl);<br> if GetLastError <> ERROR_SUCCESS then <br> memo1.lines.add('Error adjusting process privileges.'); <br> end else memo1.lines.add('Cannot find privilege value. ['+GetErrorString+']');<br> end;<br> if CancelShutdown then<br> if AbortSystemShutdown(nil) = False then <br> memo1.lines.add('Cannot abort. [/'+GetErrorString+'/]')<br> else <br> memo1.lines.add('Cancelled./')<br> else begin <br> if InitiateSystemShutdown(nil, nil, timeDelay, downQuick, Reboot) = False then<br> memo1.lines.add('Cannot go down. [/'+GetErrorString+'/]')<br> else <br> memo1.lines.add('Shutting down!/'); <br> end;<br> end <br> else begin<br> ExitWindowsEx(flgs, 0); <br> end; <br>end; <br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br> memo1.lines.add('Shutdown v0.3 for Win32 (similar to the Linux version)');<br> memo1.lines.add('(c) 2000 NeuralAbyss Software. All Rights Reserved.');<br> if HasParam('?') or (ParamCount=0) then begin<br> memo1.lines.add('Usage: shutdown [-akrhfnc] [-t secs]');<br> memo1.lines.add(' -k: don''t really shutdown, only warn.');<br> memo1.lines.add(' -r: reboot after shutdown.');<br> memo1.lines.add(' -h: halt after shutdown.');<br> memo1.lines.add(' -p: power off after shutdown');<br> memo1.lines.add(' -l: log off only');<br> memo1.lines.add(' -n: kill apps that don''t want to die.');<br> memo1.lines.add(' -c: cancel a running shutdown.');<br> end else begin<br> if HasParam('k') then warn := true;<br> if HasParam('r') then reboot := true;<br> if HasParam('h') and reboot then begin<br> memo1.lines.add('Error: Cannot specify -r and -h parameters together!');<br> Exit;<br> end;<br> if HasParam('h') then reboot := false;<br> if HasParam('n') then downQuick := true;<br> if HasParam('c') then cancelShutdown := true;<br> if HasParam('p') then powerOff := true;<br> if HasParam('l') then logoff := true;<br> DoShutdown;<br> end;<br>end;<br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br> reboot := true;<br> DoShutdown;<br><br>end;<br>end.<br>