Programmatically changing the Device Name

Screenshot of Set Device Name applicationFor some Line of Business (LOB) applications intended for tightly controlled deployment environments you may want to programatically set the Device Name of each PDA. This blog post discusses one common technique for achieving this.

Changing the Device Name

A Windows Mobile device stores the Device Name in the registry underneath the HKEY_LOCAL_MACHINE\Ident\Name value. This means we can make use of the Microsoft.Win32.Registry class to change the value and hence update the device name.

A code snippet for achieving this could take the following form.

using Microsoft.Win32;
void SetDeviceName(string deviceName)
  // Change the device name of the current Windows Mobile device
  using (RegistryKey key = Registry.LocalMachine.OpenSubkey("Ident", true))
    key.SetValue("Name", deviceName);

Verifying the change

The device’s TCP/IP stack utilises the device name as the device’s hostname. So an easy way to verify that the change has been successfully made is to ask what the current hostname is. This process is demonstrated below.

// Determine the current host name
using System.Net;
MessageBox.Show(Dns.GetHostName(), "Current Device Name");

Be aware however that certain parts of the operating system may require additional steps to be taken in order for them to read the updated information stored in the registry. Refer to the article titled “Naming a Device” available on MSDN for additional guidance.

Sample Application

[Download - 9.64 KB]

A small sample application is available for download. It demonstrates setting the device name programatically and includes two buttons to enable the user to verify that the change has been correctly made.

The first button asks the DNS subsystem for the current host name, while the second makes use of a technique discussed previously to display the Device ID control panel applet.

Another way to verify the change has been made is to simply connect the PDA to your desktop PC via ActiveSync. The main ActiveSync window displayed on the PC should display the device name in the top left hand corner.

Leave a Reply