delphi编辑hosts文件

来源:互联网 发布:淘宝店怎么开通淘金币 编辑:程序博客网 时间:2024/05/17 01:23
unit Unit2;interfaceuses  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;type  TForm2 = class(TForm)    Memo1: TMemo;    procedure FormCreate(Sender: TObject);    procedure FormClose(Sender: TObject; var Action: TCloseAction);  private    { Private declarations }  public    { Public declarations }  end;var  Form2: TForm2;implementation{$R *.dfm}procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);beginmemo1.Lines.SaveToFile('C:\Windows\System32\drivers\etc\hosts');end;procedure TForm2.FormCreate(Sender: TObject);beginmemo1.Clear;if FileExists('C:\Windows\System32\drivers\etc\hosts') then begin   memo1.Lines.LoadFromFile('C:\Windows\System32\drivers\etc\hosts');end Else begin  memo1.Lines.Add('C:\Windows\System32\drivers\etc\hosts,不存在!!!')end;end;end.

0 0