您现在的位置:首页 >> 网络通讯 >> 网络通讯 >> 内容

Delphi中如何禁止和启用Windows的代理设置

时间:2011/9/3 15:12:24 点击:

  核心提示:unit main;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, D...

unit main;

interface

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

type
  TForm1 = class(TForm)
    CheckBox1: TCheckBox;
    btnApply: TButton;
    procedure btnApplyClick(Sender: TObject);
  private
    { Private declarations }
    R            : TRegistry;
    ProxySetting : Integer;
  public
    { Public declarations }
    constructor Create(AOwner : TComponent);override;
  end;

var
  Form1: TForm1;

const
  //The registry key where the setting is stored.
  PROXY_KEY = 'Software\Microsoft\Windows\CurrentVersion\Internet Settings';
implementation

{$R *.dfm}
{------------------------------------------------------------------------------}
constructor TForm1.Create(AOwner: TComponent);
begin
  inherited;
   R := TRegistry.Create;
  try
    R.RootKey := HKEY_CURRENT_USER;
    if R.OpenKey(PROXY_KEY,False) then
    begin
      //Reading the state of the setting.
      ProxySetting := R.ReadInteger('ProxyEnable');
      case ProxySetting of
        0: CheckBox1.Checked := False;
        1: CheckBox1.Checked := True;
      end;
    end;
  finally
    R.CloseKey;
    FreeAndNil(R);
  end;
end;
{------------------------------------------------------------------------------}
procedure TForm1.btnApplyClick(Sender: TObject);
begin
 { TODO -oUser -cConsole Main : Insert code here }
  R := TRegistry.Create;
  try
    R.RootKey := HKEY_CURRENT_USER;
    if R.OpenKey(PROXY_KEY,False) then
    begin
      //Setting Proxy enable / disable.
      ProxySetting := R.ReadInteger('ProxyEnable');
      if CheckBox1.Checked then
        R.WriteInteger('ProxyEnable',1)
      else
        R.WriteInteger('ProxyEnable',0);
    end;
  finally
    R.CloseKey;
    FreeAndNil(R);
  end;
end;
{------------------------------------------------------------------------------}
end.

作者:站长 来源:转载
共有评论 0相关评论
发表我的评论
  • 大名:
  • 内容:
  • 盒子文章(www.2ccc.com) © 2024 版权所有 All Rights Reserved.
  • 沪ICP备05001939号