为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

如何在win98-win2000中禁用启用网卡

2017-11-17 7页 doc 22KB 37阅读

用户头像

is_196623

暂无简介

举报
如何在win98-win2000中禁用启用网卡如何在win98-win2000中禁用启用网卡 //如何在win98/win2000中禁用启用网卡 unit ChgEthernet; interface uses Classes, Windows, SetupApi, CfgMgr32, Cfg, SysUtils; type TNetCardStruct=record Id :DWORD; // 网卡设备号 Name :String[255]; // 网卡名 Disabled:Boolean; // 当前是否禁用 Changed :Boolean; /...
如何在win98-win2000中禁用启用网卡
如何在win98-win2000中禁用启用网卡 //如何在win98/win2000中禁用启用网卡 unit ChgEthernet; interface uses Classes, Windows, SetupApi, CfgMgr32, Cfg, SysUtils; type TNetCardStruct=record Id :DWORD; // 网卡设备号 Name :String[255]; // 网卡名 Disabled:Boolean; // 当前是否禁用 Changed :Boolean; // 是否更改过 end; PNetCardStruct=^TNetCardStruct; procedure EnumNetCards(NetDeviceList:TList); //枚举系统中的网卡 function NetCardStateChange(var NetCardPoint:PNetCardStruct;Enabled:Boolean):Boolean; //设置网卡的状态 implementation //读取系统的设备属性 function GetRegistryProperty(DeviceInfoSet: HDEVINFO;var DeviceInfoData: SP_DEVINFO_DATA; AProperty: ULONG;var Buffer: Pchar; var BufSize: ULONG): Boolean; var Temp,OldSize:DWORD; begin Result:=False;Temp:=0;OldSize:=BufSize; while not SetupDiGetDeviceRegistryProperty(DeviceInfoSet,DeviceInfoData, AProperty, Temp, PByte(Buffer), OldSize,BufSize) do begin if GetLastError()=ERROR_INSUFFICIENT_BUFFER then begin if OldSize>0 then FreeMem(Buffer,OldSize); GetMem(Buffer,BufSize);OldSize:=BufSize; end else Exit; end; Result:=True; end; procedure EnumNetCards(NetDeviceList: TList); var DevValue:String; NetCard:PNetCardStruct; Status,Problem:DWORD; Buffer:PChar; BufSize:DWORD; hDevInfo:Pointer; DeviceInfoData:SP_DEVINFO_DATA; DeviceId:DWORD; begin if Win32MajorVersion>=5 then BufSize:=0 else begin BufSize:=1024; GetMem(Buffer,BufSize); end; hDevInfo:=SetupDiGetClassDevs(nil,nil,0,DIGCF_PRESENT or DIGCF_ALLCLASSES); if DWORD(hDevInfo)=INVALID_HANDLE_VALUE then Exit; DeviceInfoData.cbSize:=sizeof(SP_DEVINFO_DATA); DeviceID:=0; while SetupDiEnumDeviceInfo(hDevInfo,DeviceId,DeviceInfoData) do begin if CM_Get_DevNode_Status(@Status,@Problem,DeviceInfoData.DevInst,0)<>CR_SUCCESS then begin Inc(DeviceID); Continue; end; if GetRegistryProperty(hDevInfo,DeviceInfoData,SPDRP_CLASS,Buffer,BufSize) then DevValue:=Buffer; if DevValue='Net' then begin if GetRegistryProperty(hDevInfo,DeviceInfoData,SPDRP_ENUMERATOR_NAME,Buffer,BufSize) then DevValue:=Buffer; if DevValue<>'ROOT' then begin new(NetCard); NetCard.Id:=DeviceId; NetCard.Name:=''; if GetRegistryProperty(hDevInfo,DeviceInfoData,SPDRP_DRIVER,Buffer,BufSize) then if GetRegistryProperty(hDevInfo,DeviceInfoData,SPDRP_DEVICEDESC,Buffer,BufSize) then NetCard.Name:=Buffer; NetCard.Disabled:=((Status and DN_HAS_PROBLEM)<>0)and(CM_PROB_DISABLED=Problem); NetCard.Changed:=false; NetDeviceList.Add(NetCard); end; end; Inc(DeviceID); end; end; function NetCardStateChange(var NetCardPoint: PNetCardStruct; Enabled: Boolean): Boolean; var hDevInfo:Pointer; DeviceInfoData:SP_DEVINFO_DATA; Status,Problem:DWORD; PropChangeParams:SP_PROPCHANGE_PARAMS; begin Result:=False; hDevInfo:=SetupDiGetClassDevs(nil,nil,0,DIGCF_PRESENT or DIGCF_ALLCLASSES); if INVALID_HANDLE_VALUE=DWORD(hDevInfo) then Exit; DeviceInfoData.cbSize:=sizeof(SP_DEVINFO_DATA); if not SetupDiEnumDeviceInfo(hDevInfo,NetCardPoint.Id,DeviceInfoData) then Exit; if CM_Get_DevNode_Status(@Status,@Problem,DeviceInfoData.DevInst,0)<>CR_SUCCESS then Exit; PropChangeParams.ClassInstallHeader.cbSize:=sizeof(SP_CLASSINSTALL_HEADER); PropChangeParams.ClassInstallHeader.InstallFunction:=DIF_PROPERTYCHANGE; PropChangeParams.Scope:=DICS_FLAG_GLOBAL; if Enabled then begin if not (((Status and DN_HAS_PROBLEM)<>0)and(CM_PROB_DISABLED=Problem)) then begin NetCardPoint.Disabled:=False; Exit; end; PropChangeParams.StateChange:=DICS_ENABLE; end else begin if ((Status and DN_HAS_PROBLEM)<>0)and(CM_PROB_DISABLED=Problem) then begin NetCardPoint.Disabled:=True; Exit; end; if not (((Status and DN_DISABLEABLE)<>0)and(CM_PROB_HARDWARE_DISABLED<>Problem)) then Exit; PropChangeParams.StateChange:=DICS_DISABLE; end; if not SetupDiSetClassInstallParams(hDevInfo,@DeviceInfoData,PSPClassInstallHeader(@Pro pChangeParams),Sizeof(PropChangeParams)) then Exit; if not SetupDiCallClassInstaller(DIF_PROPERTYCHANGE,hDevInfo,@DeviceInfoData) then Exit; if CM_Get_DevNode_Status(@Status,@Problem,DeviceInfoData.DevInst,0)=CR_SUCCESS then NetCardPoint.Disabled:=((Status and DN_HAS_PROBLEM)<>0)and(CM_PROB_DISABLED=Problem); Result:=True; end; initialization LoadSetupApi; LoadCfgMgr32; finalization UnLoadCfgMgr32; UnloadSetupApi; end. { 注:对应部分98下不支持“即插即用”的网卡,上说代码可能无效。怎样判断98下的网 卡是否支持“即插即用”,就是在设备管理器中先禁用网卡,然后启用网卡,如果系统不要求 重启就表示支持“即插即用”。}
/
本文档为【如何在win98-win2000中禁用启用网卡】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索