Search code examples
c#.netwindowwmi

Recovering Network Adapter Settings with .Net


I have a need to capture the original state/settings of network adapters in windows utilizing C#. My project requires that we make specific changes to IP/Gateway,etc. to a network adapter and then later, revert the settings to its original settings. I have been using the System.Management.ManagementObject class to pull these needed properties, but I find that when a network adapter is disabled/disconnected, I am unable to pull statically set properties (IE:IP Address,Subnet Mask,Default gateway, Preferred/Alternate DNS Settings) on the adapter UNLESS it has a connection (regardless if it is enabled/disabled).

Digging through some registry settings, I can find where I believe these settings are set, but I am unable to make a correlation from the properties on the ManagementObject and entries in the registry.

What I need to know is:

  • How to get properties set on disabled/disconnected network adapter configurations in Windows

Solution

  • the only way to do this is to query the driver and the driver for the disabled NIC is not loaded.

    When a network interface is disabled, the adapter's driver is unloaded. Without a loaded driver, Windows cannot request an address.

    Consider the disabled device as not existing at all.