0 Replies Latest reply on Jan 21, 2010 2:38 PM by dcleveland

    Using C# System.Management to change adapter settings

    dcleveland

      Hello,

      I am developing a command line utility that will allow an end user to configure the network adapters via command line.  This is a C# (.NET 2.0) application running on Window Embedded Standard 2009.  I can enumerate the IANet_PhysicalEthernetAdapters and IANet_AdapterSettings just fine.  However, I cannot figure out how to update a setting.  I'm trying something like this, but keep getting a "Generic failure" exception.

       

                          _objSetting["CurrentValue"] = newVal;
                          NetService ns = NetService.GetInstance();
                          uint clientHandle, followupAction;
                          ns.BeginApply(out clientHandle);
                          ManagementNamedValueCollection context = new ManagementNamedValueCollection();
                          context.Add("ClientSetId", clientHandle.ToString());
                          _objSetting.Put(new PutOptions(context, TimeSpan.MaxValue, true, PutType.UpdateOnly));
                          ns.Apply(clientHandle, out followupAction);

       

      The _objSetting.Put(..) is causing the exception "Generic failure".

      I appear to be getting a valid client handle from the BeginApply() function call.  After the crash, it takes a bit before I can even run this again, as I'm having to wait for that lock to timeout.  Development and testing is on Vista, but I get the same error on XP64 test machine as well.

       

      I have search the web cannot find any examples on how to change these settings using C# WMI classes.  I'm obviously missing an important step.

       

      Please help!