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:
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 http://mobilitydojo.net/files/HostsFileEditPro.exe
Windows Mobile Standard http://mobilitydojo.net/files/HostsFileEditStd.exe
Could you make a version that works on a Standard/SmartPhone WM device compared Professional/PocketPC version? This has been lacking.
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.
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..
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.
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.
Great! Thanks so much!
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!
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.
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..
Sloppiness in the QA department
I’ll fix it the next time I fire up Visual Studio.
I think I nailed the bug.
I have uploaded a new build.
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?
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.
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!
You’re right. Don’t know how that happened, but it should be fixed now.
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.
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.
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
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?