你可以参考下边的例子,在这个例子中,当系统关机时在WindowsCloseTime.txt文件中写入关键时间。<br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, StdCtrls;<br><br>type<br> TForm1 = class(TForm)<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> protected<br> procedure OnWindowsEixt(var Msg:TWMQUERYENDSESSION);message WM_QUERYENDSESSION;<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm1.OnWindowsEixt(var Msg:TWMQUERYENDSESSION);<br>var<br> f:TextFile;<br> FileHandle:Integer;<br>begin<br> //将退出时间记录在C:/WindowsCloseTime.txt文件中<br> FileHandle := FileCreate('C:/WindowsCloseTime.txt');<br> FileClose(FileHandle);<br> AssignFile(f,'C:/WindowsCloseTime.txt');<br> Rewrite(f);<br> Write(f,TimeToStr(Now));<br> CloseFile(f);<br> //<br> Msg.Result := 1;<br>end;<br><br>end. <br>