delphi 如何断开网络和连接网络

delphi如何断开网络和连接网络就想防火墙一样点断开就断开了再点开启有开启了求代码... delphi 如何断开网络和连接网络

就想防火墙一样 点断开 就断开了 再点开启有开启了

求代码
展开
 我来答
百度网友1b932d7
推荐于2016-04-26 · TA获得超过816个赞
知道小有建树答主
回答量:455
采纳率:0%
帮助的人:421万
展开全部
unit uNetworkConnection;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, ActiveX,
ComObj, Contnrs, TntWideStrUtils;
const CLSID_ConnectionManager: TGUID =
'{BA126AD1-2166-11D1-B1D0-00805FC1270E}'; IID_INetConnectionManager:
TGUID = '{C08956A2-1CD3-11D1-B1C5-00805FC1270E}';
type NETCONMGR_ENUM_FLAGS = (NCME_DEFAULT); NETCON_STATUS = (
NCS_DISCONNECTED, NCS_CONNECTING, NCS_CONNECTED, NCS_DISCONNECTING,
NCS_HARDWARE_NOT_PRESENT, NCS_HARDWARE_DISABLED,
NCS_HARDWARE_MALFUNCTION, NCS_MEDIA_DISCONNECTED, NCS_AUTHENTICATING,
NCS_AUTHENTICATION_SUCCEEDED, NCS_AUTHENTICATION_FAILED,
NCS_INVALID_ADDRESS, NCS_CREDENTIALS_REQUIRED ); NETCON_MEDIATYPE = (
NCM_NONE, NCM_DIRECT, NCM_ISDN, NCM_LAN, NCM_PHONE, NCM_TUNNEL,
NCM_PPPOE, NCM_BRIDGE, NCM_SHAREDACCESSHOST_LAN,
NCM_SHAREDACCESSHOST_RAS ); PNETCON_PROPERTIES = ^NETCON_PROPERTIES;
NETCON_PROPERTIES = record guidId: TGuid; pszwName: LPWSTR; //array
[0..255] of WCHAR; pszwDeviceName: LPWSTR; Status: NETCON_STATUS;
MediaType: NETCON_MEDIATYPE; dwCharacter: DWORD; clsidThisObject:
TGuid; clsidUiObject: TGuid; end; INetConnectionManager = interface;
INetConnection = interface; IEnumNetConnection = interface;
INetConnectionManager = interface(IUnknown)
['{C08956A2-1CD3-11D1-B1C5-00805FC1270E}'] function
EnumConnections(flag: NETCONMGR_ENUM_FLAGS; out ppv:
IEnumNetConnection): HRESULT; stdcall; end; IEnumNetConnection =
interface(IUnknown) ['{C08956A0-1CD3-11D1-B1C5-00805FC1270E}'] function
Next(celt: DWORD; out rgelt: INetConnection; pceltFetched: PULONG):
HRESULT; stdcall; function Skip(celt: ULONG): HRESULT; stdcall;
function Reset(): HRESULT; stdcall; function Clone(out ppenum:
IEnumNetConnection): HRESULT; stdcall; end; INetConnection =
interface(IUnknown) ['{C08956A1-1CD3-11D1-B1C5-00805FC1270E}'] function
Connect(): HRESULT; stdcall; function Disconnect(): HRESULT; stdcall;
function Delete(): HRESULT; stdcall; function
Duplicate(pszwDuplicateName: LPCWSTR; out ppCon: INetConnection):
HRESULT; stdcall; function GetProperties(out ppProps:
PNETCON_PROPERTIES): HRESULT; stdcall; function GetUiObjectClassId(out
pclsid: TGUID): HRESULT; stdcall; function Rename(pszwNewName:
LPCWSTR): HRESULT; stdcall; end; //Global functions procedure
GetConnectionList(pList: TStrings); function EnableConnection(Guid:
String; bEnable: Boolean): Integer;
implementation
procedure GetConnectionList(pList: TStrings);
var pManager : INetConnectionManager; pEnum : IEnumNetConnection;
pConnection : INetConnection; celtFetched : DWORD; pProperties :
PNETCON_PROPERTIES; Status : String;
begin CoCreateInstance(CLSID_ConnectionManager, nil, CLSCTX_SERVER,
IID_INetConnectionManager, pManager); if
SUCCEEDED(pManager.EnumConnections(NCME_DEFAULT, pEnum)) then begin
while (pEnum.Next(1, pConnection, @celtFetched) = S_OK) do begin
pConnection.GetProperties(pProperties); case pProperties.Status of
NCS_CONNECTED: Status := 'CONNECTED'; NCS_DISCONNECTED: Status :=
'DISCONNECTED'; NCS_CONNECTING: Status := 'CONNECTING';
NCS_HARDWARE_DISABLED: Status := 'DISABLED'; else Status := 'Others';
end; pList.Add(Format('%s|%s|%s|%s', [GUIDToString(pProperties.guidId),
pProperties.pszwName, pProperties.pszwDeviceName, Status])); end; end;
end;
// This method will enable/disable the network connection similar to
the GUI code.
// EnableConnection(L"Local Area Connection", true);
//
function EnableConnection(Guid: String; bEnable: Boolean): Integer;
var LPNcFreeNetconProperties : procedure(pProps : PNETCON_PROPERTIES)
stdcall; //LPIEnumNetConnection_EnumConnections : procedure(myob : IEnumNetConnectionj, NETCONMGR_ENUM_FLAGS flags, IEnumNetConnection * * ppEnum);
hres : HRESULT;
pMan : INetConnectionManager;
pEnum : IEnumNetConnection;
pCon : INetConnection;
count : DWORD;
done : Integer;
hmod : HMODULE;
pProps : PNETCON_PROPERTIES;
begin
result := 0;
hmod := LoadLibrary('netshell.dll');
if (hmod = 0) then
exit;
@LPNcFreeNetconProperties := GetProcAddress(hmod, 'NcFreeNetconProperties');
if (@LPNcFreeNetconProperties = nil) then
begin
FreeLibrary(hmod);
exit;
end;
pMan := nil;
hres := CoCreateInstance(CLSID_ConnectionManager, nil, CLSCTX_ALL, IID_INetConnectionManager, pMan);
if (SUCCEEDED(hres)) then
begin
hres := pMan.EnumConnections(NCME_DEFAULT, pEnum);
if (SUCCEEDED(hres)) then
begin
done := 0;
Guid := LowerCase(Guid);
while ((pEnum.Next(1, pCon, @count) = S_OK) and (done = 0)) do
begin
pCon.GetProperties(pProps);
if (SUCCEEDED(hres)) then
begin
if (LowerCase(GuidToString(pProps.guidId)) = Guid) then
begin
if (bEnable) then begin
result := pCon.Connect();
end
else
begin
result := pCon.Disconnect();
end;
done := 1;
end; //END if (wcsstr(pProps->...
LPNcFreeNetconProperties(pProps);
//pCon._Release();
end;
end; //END while
//pEnum._Release();
end;
//pMan._Release();
end;
FreeLibrary(hmod);
end;
end.

这段代码转自csnd博客http://blog.csdn.net/jh_zzz/archive/2009/01/17/3809047.aspx
百度网友8a627e7
2015-09-23 · TA获得超过304个赞
知道小有建树答主
回答量:705
采纳率:50%
帮助的人:465万
展开全部
下载一个MS的程序 DevCon 放到程序目录下,然后用delphi执行 cmd -c devcon disable *DEV_8136* 就可以关闭 型号为8136的网卡
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
none_six
2015-06-09 · TA获得超过325个赞
知道小有建树答主
回答量:479
采纳率:100%
帮助的人:369万
展开全部
可不可以用delphi通过启用与禁用网络连接来实现。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
灰灰舒儿
2015-10-08
知道答主
回答量:37
采纳率:50%
帮助的人:8.3万
展开全部
宽带连接吗?局域网连接?不行就禁用网卡再打开
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式