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 www.mobilitydojo.net, resolving to 192.168.0.1 would look like this:

image

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.

image

image

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 http://mobilitydojo.net/files/HostsFileEditPro.exe
Windows Mobile Standard http://mobilitydojo.net/files/HostsFileEditStd.exe

32 Responses to “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. TuncD

    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. TuncD

    Great! Thanks so much! :)

  7. TuncD

    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! :)

  8. 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.

  9. 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.. :-)

    |\\arco..

  10. Sloppiness in the QA department :)
    I’ll fix it the next time I fire up Visual Studio.

  11. I think I nailed the bug.
    I have uploaded a new build.

  12. Matthew

    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?

  13. 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.

  14. Luiz

    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!

  15. You’re right. Don’t know how that happened, but it should be fixed now.

  16. Kris

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

    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.

  17. 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 http://www.domain.com 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.

  18. Ilau

    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

  19. 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?

  20. Mark Henderson

    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 mydomain.com and http://mydomain.com as mentioned in the comments above and I can never hit my domain should be 192.168.8.9 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..

    Thanks,

    Mark

  21. The format for entering new host names is http://www.domain.com – 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.

  22. Court

    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?

  23. 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 – http://www.contoso.com and a valid IP address? (If you were to use invalid IP addresses that might throw an error like this.)

  24. nutz

    can you post up a cab file for those of us downloading from our phones?
    thank you..

  25. 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.

  26. nutz: The cabs are up for grab in the Downloads section.

  27. Guruprasad

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

    Please help

  1. wmpoweruser.com » Blog Archive » Utility to easily edit your Windows Mobile Hosts file
  2. Hosts File Editor for windows Mobile | Windows Mobile Freeware Pocket Pc Download and WM6 Software
  3. Static Hosts on Windows Mobile - Marco Nielsen at myITforum.com
  4. Mobile Device Manager Resources | System Center Ideas
  5. Разрешение имен в Windows Mobile « Управление мобильными устройствами
Leave a Reply

RSS for Posts RSS for Comments