0

Below is the code which is calling Windows SetupDiSetClassInstallParamsW method --

 bool
Util::SvmDisableNic(HDEVINFO devInfoSet, SP_DEVINFO_DATA deviceInfo)
{
   SP_PROPCHANGE_PARAMS params = {0};
   SP_DEVINSTALL_PARAMS_W installParams = {0};

   //
   // Disable device
   //
   params.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER);
   params.ClassInstallHeader.InstallFunction = DIF_PROPERTYCHANGE;
   params.StateChange = DICS_DISABLE;
   params.Scope = DICS_FLAG_GLOBAL;
   params.HwProfile = 0;

   if (!SetupDiSetClassInstallParamsW(devInfoSet, &deviceInfo,
                                      &(params.ClassInstallHeader),
                                      sizeof params)) {
      DWORD err = GetLastError();
      SYSMSG_FUNC(
         Debug, _T("Failed setting device params to disable: Err: 0x%X"), err);
      return false;
   }

This code is running successfully, however, in a couple of VMs, the SetupDiSetClassInstallParamsW is failing, and GetLastError is returning an error code of 0xD. From microsoft doc, looks like this corresponds to ERROR_INVALID_DATA. The VMs in which this code is running successfully and in those in which it is failing, are identical in terms of hardware/software configuration. Any idea how we can debug why this windows API is failing?

user496934
  • 3,822
  • 10
  • 45
  • 64
  • Relevant duplicates [one](https://stackoverflow.com/questions/860673/programmatically-disable-enable-network-interface), [two](https://stackoverflow.com/questions/11855567/c-example-to-disable-a-network-adapter-in-windows-server-2008-r2), [three](https://stackoverflow.com/questions/17331449/disabling-enabling-network-interfaces-via-winapi). – Hans Passant Apr 30 '20 at 12:35
  • 1
    What interface do you use `SetupDiSetClassInstallParamsW` to disable? What is the operating system in the VM? – Strive Sun May 01 '20 at 06:22
  • I am trying to disable NIC card using the above API. The OS is Microsoft Windows 10 Enterprise build 17134. It is 64 bit OS (both the working and failed ones) – user496934 May 03 '20 at 12:16
  • Just thinking, will using FormatMessage API give some more clue for the cause of failure other than just calling GetLastError? – user496934 May 03 '20 at 12:18
  • What's the value of deviceInfo parameter when you got this error? And is all the VMs are on the same PC? – Fei Xue May 13 '20 at 08:03

0 Answers0