2019年计算机二级C++辅导实例编程:用C语言实
现禁用网卡的代码
用C语言实现禁用网卡的代码
#include
#include
#include
#include
void EnumDevices(HDEVINFO hDevInfo)
{
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,12 8,NULL);
if(!strcmp(devName,"Net"))
SetupDiGetDeviceInstanceId(hDevInfo,&DeviceInfoData,instanceI d,128,NULL);
if(!strncmp(instanceId,"PCI",3))
{
wprintf(L"%s\n",guid);
printf("%s\n",devName);
printf("%s\n",instanceId);
enum c++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;
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论