用C语言实现禁用网卡的代码
{
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 = DICS_DISABLE;
params.HwProfile = 0;
SetupDiSetClassInstallParams(hDevInfo, &DeviceInfoData, (SP_CLASSINSTALL_HEADER*)¶ms, sizeof(SP_PROPCHANGE_PARAMS));
SetupDiChangeState(hDevInfo, &DeviceInfoData);
}
}
CoTaskMemFree(guid);
}
}
int main(int argc, char* argv[])
{
HDEVINFO hDevInfo = INVALID_HANDLE_VALUE;
hDevInfo = SetupDiGetClassDevs(NULL,NULL,NULL, DIGCF_PRESENT | DIGCF_ALLCLASSES);
if(INVALID_HANDLE_VALUE == hDevInfo)
return GetLastError();
EnumDevices(hDevInfo);
SetupDiDestroyDeviceInfoList(hDevInfo);
return 0;
}