Coping with Network Settings

**Updated 3/26/09 with preface

[The following article is authored by one of the Windows Embedded MVPs (Most Valuable Professionals). Our MVPs have a heavy background in Embedded systems and are a great repository of information on Windows Embedded products. We’re providing this space on our team blog as a service to our readers by allowing MVPs to share some of their knowledge with the rest of the community.]

Quite often, achieving a desired network configuration can be challenging for Windows Embedded Standard 2009 devices. This is especially true if one is not using the default DHCP setting, which always works well.

One of the first that one often encounters is setting a static IP address, as there is not a way to configure a static IP address in Target Designer. The reason for this is the way the network configuration is stored and images are deployed to all target systems. Network adapter and the corresponding software interfaces in Windows are detected during Plug & Play as well as the network initialization phase. Each Adapter/Interface pair gets a Global Unique Identifier aka GUID from the system. This identifier is unique to every target system.


All network settings get stored at several places across the registry. The picture above shows the entries under HKLM\System\CurrentControlSet\Services\tcpip\Parameters. Due to the fact that there is not a single registry that controls everything, it is not advisable to make changes directly to the registry, instead consider using an API to make the required changes.”

Static IP addresses and Cloning

One of the problems with a dedicated identifier (static IP address) is that if the configuration gets cloned, as it is done during the normal Windows Embedded Standard deployment process, the identifier automatically becomes invalid. The GUIDs created are only valid on a single system. Therefore, as soon as a cloned system starts for the first time, Plug & Play re-enumerates the adapters with new GUIDs and puts their connections into the default state, which is DHCP.
The old settings remain in the registry under the outdated GUIDs, but are not used any more.This is the reason why static IP addresses do not survive system cloning and therefore cannot be set before deployment.

Startup helpers

It would be quite bad if this were the end of the story, but there are still a few things one can do to achieve the required settings. One important fact to understand is that the new settings can only be created on the final target using only the components and features that are already built into that runtime image.
In any case, what is needed is a way to configure the network, for example, after the first boot of the device. Common techniques to accomplish this are executing a batch file or script with the help of a RunOnce key in the registry or creating a link in the Startup folder.

WMI – universal door to Windows settings
If the image deployed is feature-rich, it may have a wider range of functionality and will most probably contain the Windows Management Instrumentation (WMI) subsystem. WMI is a very capable infrastructure to access nearly all Windows settings, including network configuration. WMI can be accessed via scripting or API (e.g. via .NET) from applications and it is up to the developer to decide what the best approach is for his current circumstances. To use scripting, the following components should be included in the image:

  • Windows Command Processor (CMD.exe)
  • Windows Management Instrumentation Technologies
  • Windows Scripting Host (when scripts are used)
  • TCP/IP utilities (for testing)
  • .NET Framework or other runtimes (if application is used)

As an example, here is the VBScript code to set a static IP address:

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _

& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colNetAdapters = objWMIService.ExecQuery _

("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")

strIPAddress = Array("")

strSubnetMask = Array("")

strGateway = Array("")

strGatewayMetric = Array(1)

For Each objNetAdapter in colNetAdapters

errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)

errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)

    If errEnable = 0 Then

WScript.Echo "The IP address has been changed."


WScript.Echo "The IP address could not be changed due to an error!"

    End If

    Exit For


This code sets the first adapter found to a static address and informs the user via a popup message whether the action was successful. There is a lot more information on WMI in the MSDN library for getting started with this highly capable technology.

Network Shell

The approach shown above works well for large images, but may be problematic for smaller images due to the footprint [or size] requirements of WMI.”.
In the case of a smaller image, a utility called network shell can be leveraged to change network settings from the command line. This consumes much less footprint.
Components required are:

  • CMD - Windows Command Processor
  • Network Command Shell
  • Network Command Shell Interface Context
  • IP Router Monitor Library

If this infrastructure is available, you can do things such as set a static IP address, for example, by adding this line to a batch file or something similar:

netsh interface ip set address "Local Area Connection" static 1

There is an interesting article by Susannah Raub, which explains in more detail the usage of netsh, and there is also a complete chapter in the Windows Embedded Standard help on this topic.

Caution when Using Write Filters

Write Filters, if enabled, will have a negative effect on the persistence of the network settings. Therefore, they should be disabled before changing network settings. It is also a good practice not to enable them in the master image before sealing it. System cloning will run right before network scripts are able to kick in, so with the filters enabled the SID and network changes will not persist. Because the cloning process starts at the time the system boots, this has a very negative effect on boot performance. But, do not forget to enable the write filters after all settings have been configured! You could use the network script /application to do this after all changes were successful.

- Alexander

Alexander Wechsler

Wechsler Consulting

Technorati Tags: ,
Comments (0)

Skip to main content