title: Disabling/enabling network interfaces via WinAPI
body: <p>Here is my attempt to disable/enable network adapters on Windows:</p>
  
  <pre><code>void EnableNetDevice(bool aState, int index)
  {
    HDEVINFO NetPnPHandle;
    SP_PROPCHANGE_PARAMS PCHP;
    SP_DEVINFO_DATA DeviceData;
    NetPnPHandle = SetupDiGetClassDevs(&amp;GUID_DEVCLASS_NET, 0, 0, DIGCF_PRESENT);
  
    if (NetPnPHandle == INVALID_HANDLE_VALUE)
    {
          return;
    }
  
    DeviceData.cbSize = sizeof(SP_DEVINFO_DATA);
    SetupDiEnumDeviceInfo(NetPnPHandle, index, &amp;DeviceData);
    PCHP.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER);
  
    if (SetupDiSetClassInstallParams(NetPnPHandle,&amp;DeviceData,&amp;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,&amp;DeviceData,&amp;PCHP.ClassInstallHeader,sizeof(SP_PROPCHANGE_PARAMS));
          SetupDiCallClassInstaller(DIF_PROPERTYCHANGE,NetPnPHandle,&amp;DeviceData);
    }
  
    DeviceData.cbSize = sizeof(SP_DEVINFO_DATA);
    SetupDiDestroyDeviceInfoList(NetPnPHandle);
  }
  </code></pre>
  
  <p>The problem is <em>it works perfectly on Windows XP</em> but <strong>doesn't work on Win 7</strong> :(</p>
  
  <p>Could you help me please find the bug?</p>
  
  <p>Thank you very much!</p>