悬赏以百分请教如何禁用网卡,Win2K/Win98

ccc_wh 2002-10-24 03:49:17
悬赏以百分请教如何禁用网卡,Win2K/Win98
...全文
339 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
simpledevelop 2003-03-30
  • 打赏
  • 举报
回复
收藏
niaosuy 2003-03-28
  • 打赏
  • 举报
回复
Mark
xiaoyaolili 2003-03-21
  • 打赏
  • 举报
回复
不错,学一学。我也正好有些需要呢!
借个东风,谢了!
huangbeyond 2003-03-17
  • 打赏
  • 举报
回复
收藏
ccc_wh 2002-10-27
  • 打赏
  • 举报
回复
谢谢 flyboycsdn(飞仔) ,这几天没能上网,所以到今天才看到,也谢谢各位的参与,呵呵
用户 昵称 2002-10-25
  • 打赏
  • 举报
回复
masterz说得对
让大家都学学
vcsongs 2002-10-25
  • 打赏
  • 举报
回复
用setupdi... 禁用网卡?
masterz 2002-10-25
  • 打赏
  • 举报
回复
to flyboycsdn:
can you post your code here? so that others can learn it too.
flyboycsdn 2002-10-25
  • 打赏
  • 举报
回复
如果你想要原程序的话,留下你的email地址
我做过一个禁用启用设备(网卡)com组件
可参看windows ddk的文档。
zhenyuwzy 2002-10-25
  • 打赏
  • 举报
回复
1.拆开机箱,拨了网卡,它想用也用不了
2.如果是整合网卡,可以在BIOS里面设置禁用
3.不想拔网卡的话,在设备管理器中打开网卡的属性,在“在此硬件配置文件中禁用”打勾
flyboycsdn 2002-10-25
  • 打赏
  • 举报
回复
(续上)
×××××××××××××××××××××××××××××
BOOL CHardware::IsClassHidden(GUID *ClassGuid)
{
BOOL bHidden = FALSE;
HKEY hKeyClass;

//
// If the devices class has the NoDisplayClass value then
// don't display this device.
//
if (hKeyClass = SetupDiOpenClassRegKey(ClassGuid,KEY_READ))
{
bHidden = (RegQueryValueEx(hKeyClass,
REGSTR_VAL_NODISPLAYCLASS,
NULL, NULL, NULL, NULL) == ERROR_SUCCESS);
RegCloseKey(hKeyClass);
}

return bHidden;
}

BOOL CHardware::ConstructDeviceName(HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData, PVOID Buffer, PULONG Length)
{
if (!GetRegistryProperty(DeviceInfoSet,
DeviceInfoData,
SPDRP_DRIVER ,
Buffer,
Length))
{
if (!GetRegistryProperty(DeviceInfoSet,
DeviceInfoData,
SPDRP_DEVICEDESC ,
Buffer,
Length))
{
if (!GetRegistryProperty(DeviceInfoSet,
DeviceInfoData,
SPDRP_CLASS ,
Buffer,
Length))
{
if (!GetRegistryProperty(DeviceInfoSet,
DeviceInfoData,
SPDRP_CLASSGUID ,
Buffer,
Length))
{
*Length = (_tcslen(UnknownDevice)+1)*sizeof(TCHAR);
Buffer =(char *)malloc(*Length);
_tcscpy(*(LPTSTR *)Buffer,UnknownDevice);
}
}
}

}


return TRUE;
}

BOOL CHardware::GetRegistryProperty(HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData, ULONG Property, PVOID Buffer, PULONG Length)
{
while (!SetupDiGetDeviceRegistryProperty(DeviceInfoSet,
DeviceInfoData,
Property,
NULL,
(BYTE *)*(TCHAR **)Buffer,
*Length,
Length
))
{

if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
{
//
// We need to change the buffer size.
//
if (*(LPTSTR *)Buffer)
LocalFree(*(LPTSTR *)Buffer);
*(LPTSTR *)Buffer = (PCHAR)LocalAlloc(LPTR,*Length);
}
else
{
//
// Unknown Failure.
//

return FALSE;
}
}

return (*(LPTSTR *)Buffer)[0];

}

BOOL CHardware::StateChange(DWORD NewState, DWORD SelectedItem, HDEVINFO hDevInfo)
{
SP_PROPCHANGE_PARAMS PropChangeParams = {sizeof(SP_CLASSINSTALL_HEADER)};
SP_DEVINFO_DATA DeviceInfoData = {sizeof(SP_DEVINFO_DATA)};

//
// Get a handle to the Selected Item.
//
if (!SetupDiEnumDeviceInfo(hDevInfo,SelectedItem,&DeviceInfoData))
{

return FALSE;
}

//
// Set the PropChangeParams structure.
//
PropChangeParams.ClassInstallHeader.InstallFunction = DIF_PROPERTYCHANGE;
PropChangeParams.Scope = DICS_FLAG_GLOBAL;
PropChangeParams.StateChange = NewState;

if (!SetupDiSetClassInstallParams(hDevInfo,
&DeviceInfoData,
(SP_CLASSINSTALL_HEADER *)&PropChangeParams,
sizeof(PropChangeParams)))
{


return FALSE;
}

//
// Call the ClassInstaller and perform the change.
//
if (!SetupDiCallClassInstaller(DIF_PROPERTYCHANGE,
hDevInfo,
&DeviceInfoData))
{


return TRUE;
}


return TRUE;
}

BOOL CHardware::IsDisabled(DWORD SelectedItem, HDEVINFO hDevInfo)
{
SP_DEVINFO_DATA DeviceInfoData = {sizeof(SP_DEVINFO_DATA)};
DWORD Status, Problem;

//
// Get a handle to the Selected Item.
//
if (!SetupDiEnumDeviceInfo(hDevInfo,SelectedItem,&DeviceInfoData))
{

return FALSE;
}

if (CR_SUCCESS != CM_Get_DevNode_Status(&Status, &Problem,
DeviceInfoData.DevInst,0))
{

return FALSE;
}

return ((Status & DN_HAS_PROBLEM) && (CM_PROB_DISABLED == Problem)) ;
}

BOOL CHardware::IsDisableable(DWORD SelectedItem, HDEVINFO hDevInfo)
{
SP_DEVINFO_DATA DeviceInfoData = {sizeof(SP_DEVINFO_DATA)};
DWORD Status, Problem;

//
// Get a handle to the Selected Item.
//
if (!SetupDiEnumDeviceInfo(hDevInfo,SelectedItem,&DeviceInfoData))
{

return FALSE;
}

if (CR_SUCCESS != CM_Get_DevNode_Status(&Status, &Problem,
DeviceInfoData.DevInst,0))
{

return FALSE;
}

return ((Status & DN_DISABLEABLE) &&
(CM_PROB_HARDWARE_DISABLED != Problem));
}

STDMETHODIMP CHardware::Enable(BSTR DriverID, long *pVal)
{
BOOL ShowHidden = 0;
HDEVINFO hDevInfo = 0;
long len;
//init the value
TIndex = -1;
len = wcstombs(NULL,DriverID,wcslen(DriverID));
len = len + 1;
DrvID = (char *)malloc(len);
memset(DrvID,0,len+1);
wcstombs(DrvID,DriverID,wcslen(DriverID));


if (INVALID_HANDLE_VALUE == (hDevInfo =
SetupDiGetClassDevs(NULL,NULL,NULL,
DIGCF_PRESENT|DIGCF_ALLCLASSES)))

{

*pVal = -1;
return S_OK;
}
//get the index of drv in the set
EnumAddDevices(ShowHidden,hDevInfo);

//disable the drv

if (IsDisabled(TIndex,hDevInfo))
if (StateChange(DICS_ENABLE,TIndex,hDevInfo))
*pVal = 0;
else
*pVal = -1;
else
*pVal = 0;

if(hDevInfo)
SetupDiDestroyDeviceInfoList(hDevInfo);
return S_OK;
}

××××××××××××××××××××××××××××××××××××
以上为原程序,其实可以去找微软的ddk去看一看,里面有一个列举机器的设备和启用禁用的实例,我的这个是为了应付老板,看了例子后做了一些改动。
flyboycsdn 2002-10-25
  • 打赏
  • 举报
回复
// Hardware.cpp : Implementation of CHardware
#include "stdafx.h"
#include "NetCA_HARDWARE.h"
#include "Hardware.h"
#define UnknownDevice TEXT("<Unknown Device>")

/////////////////////////////////////////////////////////////////////////////
// CHardware

/*****************禁用设备********************************

参数说明: DriverID[in]--设备在注册表中的唯一标识
pVal[out,retval]--返回值,成功为0,失败为1
创建时间: 2002-6-21

**********************************************************/
STDMETHODIMP CHardware::Disable(BSTR DriverID, long *pVal)
{
BOOL ShowHidden = 0;
HDEVINFO hDevInfo = 0;
long len;
//init the value
TIndex = -1;
len = wcstombs(NULL,DriverID,wcslen(DriverID));
len = len + 1;
DrvID = (char *)malloc(len);
memset(DrvID,0,len+1);
wcstombs(DrvID,DriverID,wcslen(DriverID));


if (INVALID_HANDLE_VALUE == (hDevInfo =
SetupDiGetClassDevs(NULL,NULL,NULL,
DIGCF_PRESENT|DIGCF_ALLCLASSES)))

{

*pVal = -1;
return S_OK;
}
//get the index of drv in the set
EnumAddDevices(ShowHidden,hDevInfo);

//disable the drv

// if ((IsDisableable(TIndex,hDevInfo))&&(!(TIndex==-1)))
if (!IsDisabled(TIndex,hDevInfo))
if (IsDisableable(TIndex,hDevInfo))
if (StateChange(DICS_DISABLE,TIndex,hDevInfo))
*pVal = 0;
else
*pVal = -1;
else
*pVal = 1;
else
*pVal = 0;

if(hDevInfo)
SetupDiDestroyDeviceInfoList(hDevInfo);
return S_OK;
}

BOOL CHardware::EnumAddDevices(BOOL ShowHidden, HDEVINFO hDevInfo)
{
DWORD i, Status, Problem;

LPTSTR IOName=NULL;
DWORD len=0;
SP_DEVINFO_DATA DeviceInfoData = {sizeof(SP_DEVINFO_DATA)};



//
// Enumerate though all the devices.
//
for (i=0;SetupDiEnumDeviceInfo(hDevInfo,i,&DeviceInfoData);i++)
{
//
// Should we display this device, or move onto the next one.
//
if (CR_SUCCESS != CM_Get_DevNode_Status(&Status, &Problem,
DeviceInfoData.DevInst,0))
{

continue;
}

if (!(ShowHidden || !((Status & DN_NO_SHOW_IN_DM) ||
IsClassHidden(&DeviceInfoData.ClassGuid))))
continue;



//
// Get a friendly name for the device.
//

ConstructDeviceName(hDevInfo,&DeviceInfoData,
&IOName,
(PULONG)&len);
if (strcmp(IOName,DrvID) == 0)
{
TIndex = i;
return TRUE;
}
}
return TRUE;

}

2,641

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 硬件/系统
社区管理员
  • 硬件/系统社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧