Sunday, October 19, 2008

Setting the name of a Windows Mobile device programmatically

Setting the name of a Windows Mobile powered device can be achieved by manipulating the registry. Since CF 2.0 we have had the luxury of a Registry managed wrapper, so there is no need to P/Invoke the registry API.

This post shows a simple example how to read and update the name of the device - which is stored in the registry.

I've written a simple bit of code that looks like the following:
using Microsoft.Win32;
public partial class Form1 : Form
private const string IDENTITY = @"HKEY_LOCAL_MACHINE\Ident";
private const string NAME = "Name";
public Form1()


private void apply_Click(object sender, EventArgs e)
Registry.SetValue(IDENTITY, NAME, deviceName.Text);

private void Form1_Load(object sender, EventArgs e)
deviceName.Text = (string)Registry.GetValue(IDENTITY, NAME, "NAME");
The form looks like the following:

Mobile app pre-change

This can also been seen from the Settings\System\About\Device ID applet:

Device name pre-change

Also this can be seen via the Windows CE Remote Registry Editor (CE Remote Tools):

Now we simply change the "MyDevice" to "NewDeviceName" and click the Apply button. Our change is propagated instantly if we go and check the settings applet again:

It's as simple as that!

No comments: