title: WMI Win32_NetworkAdapterConfiguration "EnableStatic" call fails with return result 0x80041003
body: <p>I'm having trouble assigning a static IP address to a device that gets attached to my system and advertises a Network Adapter.  Whenever I call EnableStatic on the device, with the IP and subnet mask, it returns the error code 0x80041003, which I believe means "Access Denied".  I can change the IP address in Windows without requiring elevation.</p>
  
  <p>The code I'm using to set the IP address looks like this:</p>
  
  <pre><code> /// &lt;summary&gt;
      /// Set's a new IP Address and subnet mask for the adapter with the given description.
      /// &lt;/summary&gt;
      /// &lt;param name="description"&gt;Description string used to ID the adapter.&lt;/param&gt;
      /// &lt;param name="ip_address"&gt;The IP Address.&lt;/param&gt;
      /// &lt;param name="subnet_mask"&gt;The Submask IP Address&lt;/param&gt;
      public static void SetIP(string description, string ip, string mask)
      {
          ManagementClass findAdapters = 
                                      new ManagementClass("Win32_NetworkAdapterConfiguration");
          ManagementObjectCollection adapters = findAdapters.GetInstances();
  
          foreach (ManagementObject adapter in adapters)
          {
              string name = (string)adapter["Description"];
  
              if (name != description)
              {
                  continue;
              }
  
              try
              {
                  ManagementBaseObject newIP = 
                                             adapter.GetMethodParameters("EnableStatic");
  
                  newIP["IPAddress"] = new string[] { ip };
                  newIP["SubnetMask"] = new string[] { mask };
  
                  ManagementBaseObject setIP = 
                                              adapter.InvokeMethod("EnableStatic", newIP, null);
  
                  UInt32 result = (UInt32)(setIP["returnValue"]);
              }
              catch (Exception)
              {
                  throw;
              }                
          }
      }
  </code></pre>
  
  <p>I have hunted around the internets looking for solutions.  The one that looked most likely was that I needed to do something like CoInitializeSecurity before everything got up and running.  But this seems odd to me.  I'm using the WMI namespace, if WMI is somehow dependent on things like this, surely that should be in the namespace too?</p>
  
  <p>There is something I'm missing here....</p>
  
  <p>btw running Windows 7 on a domain as User but am a local administrator if that helps!</p>