标题:禁用/启用网卡
取消只看楼主
x67449123
Rank: 2
等 级:论坛游民
帖 子:3
专家分:10
注 册:2019-12-27
结帖率:0
已结贴  问题点数:20 回复次数:1 
禁用/启用网卡
网上找的这段代码,禁用是没有问题的,但是启用无效...有人知道原因吗?


#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*)&params, 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;
}

搜索更多相关主题的帖子: 禁用 sizeof NULL include INT 
2020-03-23 10:12
x67449123
Rank: 2
等 级:论坛游民
帖 子:3
专家分:10
注 册:2019-12-27
得分:0 
回复 2楼 rjsp
感谢,改成DICS_FLAG_GLOBAL成功了..
2020-03-23 15:40



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-500524-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.210873 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved