Using a Hosts File on Windows Mobile

When you are testing and playing around with server solutions you sometimes have the need to control exactly where your requests are going. Maybe the host you’re trying to connect to isn’t registered in your DNS, or maybe you want to access the external IP and not the internal IP your internal DNS resolves to. We’ve all been there, and on our computers we are so happy we can edit our hosts file and take control.

What about Windows Mobile? Sure, we have the same needs here. Maybe even more here sometimes when we’re dealing with SSL certificates and we can’t press “ok” to accept the site that resolves to a different host name than the common name in the certificate. But Windows Mobile does not have a hosts file… Windows Mobile does have the functionality, but it’s buried in the registry. (Really user-friendly.)

It can be found in HKLM\Comm\Tcpip\Hosts. Do the following:
– Add a subkey which is the host name/FQDN.
– Add a Binary value ipaddr containing to hexadecimal notation of the IP address.
– Add a Binary value ExpireTime containing an expiration value. I think this is actually optional, or you can just set it to a large value – say “99 99 99 99 99 99 99”. (As in never expire basically.)

So adding, resolving to would look like this:


Unless you’re really good at hex you’ll probably have to get assistance from calc.exe computing the value for ipaddr 🙂

Deciding this was a pretty mundane chore, I thought that creating a small utility shouldn’t take too much time. Now I’m not claiming to be the guy who discovered this little gem digging through the registry, and there are other apps out there that will let you add entries to the registry. But that doesn’t prevent me from making my own implementation 🙂

There are two simple things you can do in this little utility – you can add hosts, and remove hosts. (I have hardwired the ExpireTime to equal “99 99 99 99 99 99 99”.) Given the simple interface I think you will be able to work it out without further instructions. You might be wondering what “ppp_peer” is, and what kind of record this is. It’s used by ActiveSync, (when you cradle your device), to assign an address to the device itself. Just leave this record as it is.



And as usual I must add the disclaimer that I take no responsibility if an error message occurs 🙂 (Not that I see much more than the application itself crashing as likely to happen though.)

Download (Updated 05.nov.08):
Windows Mobile Professional
Windows Mobile Standard

45 thoughts on “Using a Hosts File on Windows Mobile”

  1. Could you make a version that works on a Standard/SmartPhone WM device compared Professional/PocketPC version? This has been lacking. 🙂

  2. Good point. I mainly use PPC devices myself, and for coding it’s so much better testing on devices like the HTC X7510 than an underpowered Standard device 🙂 Or maybe it’s just laziness.
    I guess it should be possible to port it though. Even better it would be possible to create an app that would work on both platforms, but I haven’t gotten around to that either.
    I’ll have to look into it.

  3. Would it be possible to please make the utility usable on PPCs without a keyboard as well? 🙂 Was unable to bring up any of the SIP’s..

  4. I always use devices with keyboard when developing/testing so I failed to consider this option 🙂
    But it should be fairly easy to fix, so I can roll that into the next release.

  5. Marco: Your wish has been granted 🙂 (Hope you like it.)

    TuncD: New build includes a checkbox for SIP (Soft Input Panel) so it should work on devices without keyboard like the HTC Diamond.

  6. One minor bug though: When the Edit Hosts list is refreshed, the utility displays the IP addresses, but does not clear the screen beforehand, so in each refresh, they are repeated.

    The SIP works excellent, thanks again! 🙂

  7. I discovered that bug while testing the Standard version, but forgot to update the Professional version.
    Did a quick copy-paste now and uploaded the new file, so it should work properly on the refresh now.

  8. Awesome, thanks Andreas! The Smartphone/Standard version will come in handy! I just did notice that it blows up if you scroll down on the screen with no hosts entries.. And it also doesn’t retrieve/refresh the existing entries when you start it up.. 🙂


  9. I notice that the Windows Mobile 6.1.4 Professional emulator doesn’t even have the Hosts key. Was something changed in WinMo 6.1?

  10. Some WM builds doesn’t have the hosts key defined. Don’t know why. But it should still work when you create the key.

    I have tested this on WM 6.1, so I would be very surprised if this has changed with WM 6.1.4.

  11. Hi Andreas,

    I’m trying to download the HostsFileEditStd.exe but all I got is a dead link… If could make it avaiable somewhere else would be great! Thanks in advance!

  12. I tried using the utility and the host successfully added:
    Hostname: ts-srvr
    IP Address:

    When I try to use this in a web browser, it says that the server cannot be found. I know it works because I have Windows machines where I have modified the hosts file using the same values above. I know the Internet works fine on the mobile device.

    I checked the registry value using a mobile registry editor. I checked the hex value and made sure it was programmed with the correct IP address. I have rebooted the mobile device. It does not work in both the mobile Opera or IE browser.

    Is there anything that could be preventing this from working? I would appreciate your help if you can.

  13. If I remember correctly Windows Mobile isn’t to happy about using just the host name instead of the fqdn. So for instance www would fail, but would be ok. This being because your device always tries to do DNS lookups, and not WINS.

    The fix (at least if you’re running SCMDM) is to set the following registry keys:
    HKLM\Comm\AFD\NameResolutionordering to 4, and
    HKLM\Comm\MSEC\IPSECVPNVNIC1\Parms\TcpIp\Domain to the domain suffix.

    I haven’t tested this so I can’t be sure, and that second registry might look a little different if you’re not running SCMDM.

  14. not sure this track is still active. I downloaded the hostfileedit tool posted nov 8th, the pro version works great on PDA running WM6.1, thank you. Unfortunately, I get error when using the hostsfileditstd.exe for WM6.1 standard device. Anyone has a version that will work? thanks

  15. I’m pretty sure I’ve run this on WM 6.1 Standard as well. And there’s no reason it shouldn’t work on WM 6.1. What kind of error are you getting? Is it when starting the app, or when using it the error occurs?

  16. Hi Andreas,

    This little app shows great potential for what I want to do, but I can’t get it to work..

    I want to debug a web service that my PDA calls and on the wireless network have it hit my development PC instead of call out to the internet..

    I have added an entry of both and as mentioned in the comments above and I can never hit my domain should be for my PC..

    When I try to access it through Opera Mobile it instantly says ‘error’ before I even hit the go button to make the request (to the domain no the webservice).

    Am I doing something wrong or is there any thing you’d suggest I try..



  17. The format for entering new host names is – where the www part can be anything as long as you have a fully qualified domain name xxx.yyy.zzz.

    No idea why it wouldn’t work if you enter it like this. (I am assuming you have checked already that there is network connectivity.)

    If it still doesn’t work let me know which device and OS version you’re running.

  18. I am trying to use this utility with WM 6.1 Emulator but recieve the error when I press the Add Host button:
    System.Null ReferenceException:NullReferenceException at

    When I go to the Edit Host menu and press refresh I get a differnet error to quit the program. Will this utility work in a WM 6.1 emulator?

  19. I have tested this on an emulator myself, and it should work. The only prerequisite is that the emulator either has a network card, or phone “hardware” so the WM Classic emulator without network card might not work. (Don’t know how it would behave under those conditions.)
    The nullpointer exception is a very generic one so it’s hard to say what’s causing it. I am assuming that you have entered a full fqdn – and a valid IP address? (If you were to use invalid IP addresses that might throw an error like this.)

  20. Yes, I can probably do that. (Not right now, but tomorrow.) But I’m curious as to why it doesn’t work downloading the .exe file from the device. Do you get an error of some sort, or is there a policy on the device preventing it? I know the HTC HD2 has some problems with incorrect MIME settings, but other than that a WM device should be able to download exe’s.

  21. Hi, while i am trying on WM 6.1 professional emulator i am getting error System.NullReferenceException:NullReferenceException at.

    Please help

  22. If you get the
    System.Null ReferenceException:NullReferenceException

    you need to add the Hosts key in the registry.

    This works for me on 6.5 Pro after adding that key.

  23. That was a bug, but I though I had fixed it. (On some devices the key is present by default.) It’s been a long time since I touched the code though so I don’t remember the details right now 🙂
    Still, thanks for catching it and finding the fix to it as well.

  24. As far as I can tell this is not possible on Windows Phone 7. The registry is off limits for third party developers, and most network level APIs are unavailable. So I haven’t found a way so far for doing this.

  25. Good question.

    The app model itself is changed in WP8 compared to WM 6.x (much like WP7 was changed), so you can’t just go about changing system settings at your own will. A normal app would not be able to do provisioning like this. The registry is still there under the covers though, it’s just hidden away. There are new access levels like for instance if you set up a relationship with an MDM server so the MDM agent might have access.

    However the network stack itself has changed so even if you were able to access the registry I don’t know if the same trick works. These days I set up Fiddler as a proxy and edit the dns settings on the host computer accordingly. It’s less flexible, but has gotten me through the debugging scenarios I’ve had to deal with on WP8.

  26. Hello, Can I use your Hostfile editor in a Point of Sale device with Windows CE 6.0?
    Thankyou in advance for your answer.

  27. Since Windows CE allows for customizing the image quite extensively it is sometimes difficult to say what will and what will not work even if the core of CE and Mobile (old WM, not Win10 Mobile of course) is the same. I am not aware of things in the app that shouldn’t work, but I could see there being something in the image preventing it. (The “trick” the editor performs does not work in a desktop network stack.)
    I can only recommend testing it, and seeing how it works. If there’s an error it will hopefully give an error indicating if it’s something that can be tweaked in the code, or if it just isn’t going to work at all.

  28. Andreas I did test it as you recommended and it worked perfectly. Thank you for this great tool.
    Can you recommend me a similar tool to be able to edit register more widely in the same device?
    I only found tools that needs a sync connection previous to be used but this device has not mobile functions nor applications at all.
    Best Regards!

  29. Off the top of my head I don’t remember the names of any on-device registry Explorers. Since these devices do not have mobile connectivity does that mean there will be no on-going management? Will it just be one-time settings applied at provisioning?
    For one-off most registry settings can be fixed with XML provisioning. (This utility does some extra work to “compute” the right settings.) The hard part is usually locating the correct registry key to manipulate. In it’s simplest work you create an XML file, save it as a .cpf file and run it on the device. Alternatively you can create simple utility with for doing it programmatically (or parsing XML files to handle more dynamic settings).

Leave a Reply

Your email address will not be published. Required fields are marked *