自己设置的开机启动 关机提示程序

    技术2022-05-11  16

     unit Unit3;

    interface

    uses   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,   Dialogs, StdCtrls,Registry;

    type   TForm3 = class(TForm)     Label1: TLabel;        Button1: TButton;     Button2: TButton;     Memo1: TMemo;     procedure FormCreate(Sender: TObject);     procedure Button1Click(Sender: TObject);     procedure Button2Click(Sender: TObject);   private

      procedure QueryEndSession(var Msg:TMessage);

      Message WM_QueryEndSession;

        { Private declarations }   public     { Public declarations }   end;

    var   Form3: TForm3;   i:Integer;

    implementation

    {$R *.dfm}

     

     

    procedure TForm3.QueryEndSession(var Msg: TMessage);

    var j:Integer; begin

           j:=1;        if j<>i then                  begin           Form3.Visible:=true;

              Memo1.ScrollBars:=ssBoth;           Memo1.Lines.LoadFromFile('d:/e.txt');

              Msg.Result:=0;

              end           else

              Msg.Result:=1;

     

     

     

    end;

     

     

     

     

     

     

    procedure TForm3.Button1Click(Sender: TObject); begin

         Form3.Hide;

     

     

    end;

     

     

    procedure TForm3.Button2Click(Sender: TObject);

    begin

        i:=1;

      

       WinExec('shutdown -s -t 0', sw_Show);

     

    end;

    procedure TForm3.FormCreate(Sender: TObject);

    var

    reg:TRegistry;

     

     {  var

        hToken:THandle;     Tkp:TTokenPrivileges;     zero:DWORD;   } begin

      {      OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,hToken);

             LookupPrivilegeValue(nil,'SeShutdownPrivilege',tkp.Privileges[0].Luid);

             Tkp.PrivilegeCount :=1;

             Tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;

              AdjustTokenPrivileges(hToken,False,Tkp,SizeOf(TTokenPrivileges),nil,Zero);

        }

          i:=0;       Memo1.Lines.LoadFromFile('d:/d.txt');

          reg:=tregistry.Create;       reg.RootKey:=HKEY_LOCAL_MACHINE;       reg.OpenKey('SOFTWARE/Microsoft/Windows/CurrentVersion/Run',true);       reg.WriteString('信息','C:/Documents and Settings/Administrator/My Documents/RAD Studio/Projects/yitutong.exe');

     

          reg.CloseKey;       reg.Free;

     

     

    end;

    end.

     

     

    注意 此程序用一个全局变量i的值, 来判断是否需要关机

     

     

     如果i的值与j不同

     则不关机

     如果相同

     则关机

     

    所以我们可以在另一个事件中设置全局变量i的取值,然后将它与其它事件中的局部变量做比较,来控制选择分支

     

     

    =====================

     

     

    ^^!!!  可惜源程序找不到了 DELPHI 也就学习了那几天 无法重新编译了  看看以后还有米有心情再调试吧

     

     


    最新回复(0)