这是我在 Windows 上禁用/启用网络适配器的尝试:
void EnableNetDevice(bool aState, int index)
{
HDEVINFO NetPnPHandle;
SP_PROPCHANGE_PARAMS PCHP;
SP_DEVINFO_DATA DeviceData;
NetPnPHandle = SetupDiGetClassDevs(&GUID_DEVCLASS_NET, 0, 0, DIGCF_PRESENT);
if (NetPnPHandle == INVALID_HANDLE_VALUE)
{
return;
}
DeviceData.cbSize = sizeof(SP_DEVINFO_DATA);
SetupDiEnumDeviceInfo(NetPnPHandle, index, &DeviceData);
PCHP.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER);
if (SetupDiSetClassInstallParams(NetPnPHandle,&DeviceData,&PCHP.ClassInstallHeader,sizeof(SP_PROPCHANGE_PARAMS)))
{
PCHP.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER);
PCHP.ClassInstallHeader.InstallFunction = DIF_PROPERTYCHANGE;
PCHP.HwProfile = 0;
PCHP.Scope = DICS_FLAG_CONFIGSPECIFIC;
if (aState) PCHP.StateChange = DICS_ENABLE;
else PCHP.StateChange = DICS_DISABLE;
SetupDiSetClassInstallParams(NetPnPHandle,&DeviceData,&PCHP.ClassInstallHeader,sizeof(SP_PROPCHANGE_PARAMS));
SetupDiCallClassInstaller(DIF_PROPERTYCHANGE,NetPnPHandle,&DeviceData);
}
DeviceData.cbSize = sizeof(SP_DEVINFO_DATA);
SetupDiDestroyDeviceInfoList(NetPnPHandle);
}
问题是它在 Windows XP 上完美运行,但在 Win 7 上无法运行:(
你能帮我找出错误吗?
非常感谢!