禁用/启用网卡
网上找的这段代码,禁用是没有问题的,但是启用无效...有人知道原因吗?#include <stdio.h>
#include <windows.h>
#include <Setupapi.h>
#include <objbase.h>
#pragma comment(lib,"Setupapi.lib")
VOID EnumDevices(HDEVINFO hDevInfo ,INT State)
{
SP_DEVINFO_DATA DeviceInfoData = { sizeof(SP_DEVINFO_DATA) };
LPOLESTR guid;
CHAR devName[128];
CHAR instanceId[128];
for (INT i = 0; SetupDiEnumDeviceInfo(hDevInfo, i, &DeviceInfoData); i++)
{
StringFromCLSID(DeviceInfoData.ClassGuid, &guid);
SetupDiClassNameFromGuid(&DeviceInfoData.ClassGuid, devName, 128, NULL);
if (!strcmp(devName, "Net"))
{
SetupDiGetDeviceInstanceId(hDevInfo, &DeviceInfoData, instanceId, 128, NULL);
if (!strncmp(instanceId, "PCI", 3))
{
wprintf(L"%s\n", guid);
printf("%s\n", devName);
printf("%s\n", instanceId);
SP_PROPCHANGE_PARAMS params = { sizeof(SP_CLASSINSTALL_HEADER) };
params.ClassInstallHeader.InstallFunction = DIF_PROPERTYCHANGE;
params.Scope = DICS_FLAG_CONFIGSPECIFIC;
params.StateChange = State;
params.HwProfile = 0;
SetupDiSetClassInstallParams(hDevInfo, &DeviceInfoData, (SP_CLASSINSTALL_HEADER*)¶ms, sizeof(SP_PROPCHANGE_PARAMS));
SetupDiChangeState(hDevInfo, &DeviceInfoData);
}
}
CoTaskMemFree(guid);
}
}
INT main()
{
HDEVINFO hDevInfo = INVALID_HANDLE_VALUE;
hDevInfo = SetupDiGetClassDevs(NULL, NULL, NULL, DIGCF_PRESENT | DIGCF_ALLCLASSES);
if (INVALID_HANDLE_VALUE == hDevInfo)
return GetLastError();
EnumDevices(hDevInfo, DICS_ENABLE); //禁用:DICS_DISABLE,启用:DICS_ENABLE
SetupDiDestroyDeviceInfoList(hDevInfo);
return 0;
}