unit UPublicDef;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Shell32_TLB, StdCtrls, Menus;
const
DiscVerb = '禁用(&B)';
ConnVerb = '启用(&A)';
function GetNetLinkList(var list:TStrings):BOOLEAN;
function ExcNetLinkMenu(const AdapterName,MenuName:String):BOOLEAN;
//function CheckNetLink
implementation
{------------------------------------------------
/*列举本地连接*/
------------------------------------------------}
function GetNetLinkList(var list:TStrings):BOOLEAN;
var
Shell:TShell;
ControlPanel:Folder;
Item:FolderItem;
i:integer;
begin
Result:= FALSE;
if list = nil then
exit;
Shell:=TShell.Create(Application);
if Shell = nil then
exit;
ControlPanel:=Shell.NameSpace(ssfCONTROLS);
for i:=0 to ControlPanel.items.Count -1 do
begin
Item:=ControlPanel.items.Item(i);
if (Item.Name = '网络连接') then
begin
ControlPanel:=Folder(Item.GetFolder);
break;
end;
end;
for i:=0 to ControlPanel.items.count-1 do
begin
Item:= ControlPanel.items.Item(i);
if Pos('本地连接',Item.Name)>0 then
List.Add(Item.Name);
end;
FreeAndNil(shell);
Result:= TRUE;
end;
{------------------------------------------------
/*操作本地连接*/
------------------------------------------------}
function ExcNetLinkMenu(const AdapterName,MenuName:String):BOOLEAN;
var
Shell:TShell;
ControlPanel:Folder;
Item:FolderItem;
i,j:integer;
Verb:FolderItemVerb;
begin
Result:= FALSE;
Shell:=TShell.Create(Application);
if Shell = nil then
exit;
ControlPanel:=Shell.NameSpace(ssfCONTROLS);
for i:=0 to ControlPanel.items.Count -1 do
begin
Item:=ControlPanel.items.Item(i);
if (Item.Name = '网络连接') then
begin
ControlPanel:=Folder(Item.GetFolder);
break;
end;
end;
for i:=0 to ControlPanel.items.count-1 do
begin
Item:=ControlPanel.items.Item(i);
if (Item.Name = AdapterName) then
begin
for j:=0 to Item.Verbs.Count -1 do
begin
Verb:=Item.Verbs.Item(j);
if (Verb.Name = MenuName) then
begin
Verb.DoIt ;
Result:=TRUE;
break;
end;
end;
break;
end;
end;
FreeAndNil(shell);
end;
end.
unit UHookFrm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, ExtCtrls, ToolWin, ImgList,UPublicDef;
type
TInstallHook=function :Boolean;Stdcall;
TUnHook=function :Boolean;Stdcall;
TFireWallFrm = class(TForm)
StatusBar1: TStatusBar;
ControlBar1: TControlBar;
Panel1: TPanel;
Panel2: TPanel;
Button1: TButton;
Button2: TButton;
ToolBar1: TToolBar;
ControlBar2: TControlBar;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
ToolButton3: TToolButton;
ToolButton4: TToolButton;
ImageList1: TImageList;
Panel3: TPanel;
NetLinkList: TComboBox;
DisconNetLink: TCheckBox;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure DisconNetLinkClick(Sender: TObject);
private
{ Private declarations }
InstallHook:TInstallHook;
UnHook:TUnHook;
Procedure GetNetLink;
public
{ Public declarations }
end;
var
FireWallFrm: TFireWallFrm;
implementation
{$R *.dfm}
procedure TFireWallFrm.Button1Click(Sender: TObject);
var
DllHandle:LongWord;
begin
DllHandle:=LoadLibrary('Hook.dll');
if DllHandle>0 then
begin
@InstallHook:=GetProcAddress(DllHandle,'InstallHook');
@UnHook:=GetProcAddress(DllHandle,'UnHook');
if (@InstallHook=Nil) or (@UnHook=nil) then
begin
showmessage('No Add');
Exit;
end else
begin
if InstallHook then showmessage('y')
else showmessage('n');
end;
end else
begin
showmessage('no Dll');
Exit;
end;
end;
procedure TFireWallFrm.Button2Click(Sender: TObject);
begin
UnHook;
end;
procedure TFireWallFrm.FormCreate(Sender: TObject);
begin
GetNetLink;
end;
procedure TFireWallFrm.DisconNetLinkClick(Sender: TObject);
begin
if Trim(NetLinkList.Text)='' then
begin
MessageBox(Handle,'没有选择网络连接!','注意!',Mb_Ok+MB_ICONERROR);
Exit;
end;
if DisconNetLink.Checked then ExcNetLinkMenu(Trim(NetLinkList.Text),DiscVerb)
else ExcNetLinkMenu(Trim(NetLinkList.Text),ConnVerb);
end;
procedure TFireWallFrm.GetNetLink;
var
NetLink:TStrings;
begin
NetLink:=TStringList.Create ;
GetNetLinkList(NetLink);
NetLinkList.Items:=NetLink;
FreeAndNil(NetLink);
end;
end.