Fully reset Network interface card

Giganews Newsgroups
Subject: Fully reset Network interface card
Posted by:  John Jarrett (jjarre…@hon-dah.com)
Date: Thu, 12 Jun 2008

Good day!

I need to fully reset, (disable then enable) the NIC(s) in a PC just as if a
user had clicked the NIC's disable then enable menu buttons.

I have used the code/procedures below, which utilize the Windows XP firewall
control ActiveX, hnetcfg.dll.

This works very well but ONLY under XP and above. (You will have to import
the hnetcfg.dll as an Active X (NETCONLib_TLB). The dll is found under
system32).

I need to do this same action in Windows 2000, and above, XP, 2003, Vista
and etc. You can't grab the dll and import the it into Windows 2000 as it is
specific to the XP/Vista firewall controls.

Can anyone assist with some code, hints, tips or tricks?

Thanks a bunch for any help.

John

uses OleServer, NETCONLib_TLB, activeX, ComObj; procedure ResetNIC(const
aConnection: string);var  pEnum: IEnumVariant;  vNetCon: OleVARIANT;
dwRetrieved: Cardinal;  pUser: NETCONLib_TLB.PUserType1;begin  try    pEnum
:= ( NetSharingManager.EnumEveryConnection._NewEnum as IEnumVariant);
while (pEnum.Next(1, vNetCon, dwRetrieved) = S_OK) do    begin
(IUnknown(vNetCon) as INetConnection).GetProperties(pUser);      if
pUser.pszwName = aConnection then      begin        (IUnknown(vNetCon) as
INetConnection).Disconnect;        (IUnknown(vNetCon) as
INetConnection).Connect;        delay(2000);        break;      end;
end;  finally  end;end; procedure GetConnectionList(Strings : TStrings);var
pEnum: IEnumVariant;  vNetCon: OleVARIANT;  dwRetrieved: Cardinal;  pUser:
NETCONLib_TLB.PUserType1;  NetCon : INetConnection;begin  Strings.Clear;
pEnum := ( NetSharingManager.EnumEveryConnection._NewEnum as IEnumVariant);
while (pEnum.Next(1, vNetCon, dwRetrieved) = S_OK) do  begin
(IUnknown(vNetCon) as INetConnection).GetProperties(pUser);    NetCon :=
(IUnknown(vNetCon) as INetConnection);      if (pUser.Status in
[NCS_CONNECTED,NCS_CONNECTING]) and        (pUser.MediaType in
[NCM_LAN,NCM_SHAREDACCESSHOST_LAN,NCM_ISDN] ) then
Strings.Add(pUser.pszwName );  end;end;

Replies