Archive for the ‘Utilities’ Category.

Mobile development: pocketHosts-Edit Windows Mobile hosts entries

PocketPC and Windows Mobile does not support a hosts file as desktop windows. As I recently had to add an entry for a virtual machine running Mini SAP (Netweaver 7.01 Trial) I stumbled about how to add a host entry to a windows mobile device.

pocketHosts

The platform builder help gives the details about how host entries are organized:

Host Name

The host name can be configured through the HKEY_LOCAL_MACHINE\Comm\Tcpip\Hosts subkey. When an application calls gethostbyname or getaddrinfo, the registry is queried first, before a DNS or WINS request is sent. If the host name is found in the registry, the registry values are returned.

The following table shows the values for the HKEY_LOCAL_MACHINE\Comm\Tcpip\Hosts\<Host Name> subkey.

Value : type Description
Aliases : REG_MULTI_SZ This value stores the aliases by which this host is known.
ExpireTime : REG_BINARY If the current time, obtained by calling GetCurrentFT, exceeds the value in ExpireTime, the entire Host Name subkey is deleted the next time that gethostbyname is called. The length of this value is 8 bytes.
ipaddr : REG_BINARY This value stores the IPv4 addresses associated with this host name. The length of this value is 4 bytes per address.
ipaddr6 : REG_BINARY This value stores the IPv6 addresses associated with this host name. The length of this value is 20 bytes per address (16 bytes for address and 4 bytes for Scope ID).

So, there is no simple hosts file.

Continue reading ‘Mobile development: pocketHosts-Edit Windows Mobile hosts entries’ »

Mobile Development: A remote cpu monitor and cpu usage analysis

cpumon2 and cpumonRcv

Although this project is not yet finished, the main function works very well: viewing cpu usage remotely and capture data to database for later analysis.

Some of the ideas and code is inspired by a cpu usage article at http://www.codeproject.com/Articles/159461/Mobile-Processor-Usage. Further on I got more questions the last days like “Why is app x running slow?” or “When I start that app, the system gets slow and taskmanager shows a high cpu usage.”.

Here are two tools to capture cpu usage of a windows mobile device remotely via a TCP/IP connection.

cpumon2   cpumonRcv

excel-barchart

Before you read on, the code is by far not perfect and there are still many improvements possible. But if you need a working remote cpumon, here we go…

Continue reading ‘Mobile Development: A remote cpu monitor and cpu usage analysis’ »

Mobile Development: AutoHide Windows Mobile Device Center 2

In an earlier post I wrote about a tool to autohide the annoying WMDC window. As a developer I dont like to keep WMDC come up every time I connect a device. I just need to know, if the device is connected or not.

Fortunately, Henkie leaved a comment about a usefull alternative for WMDC. But as commented here, no visual control of the connection.

Now I started to think about a small tool to have a visual control of WMDC connected or not. I had to use RAPI either provided by MS or via OpenNetCF.Desktop.Communication. Although the OpenNETCF one works OK, I was not satisfied, as it was impossible to get a connection status without disconnect/connect. So I went back to WIN32 API and wrote this small tool based on DeviceInfo sample of Windows Mobile 6 SDK.

First I again messed up with notification icons in Windows 7 (64bit). But the icon may be removed or not, depending on Windows 7 decisions I dont know.

So the tool uses a simple window and an icon to let you know the connection status.

Just start the tool and the icon and edit window background will show, if device is connected or not. The application icon in the title bar as in the taskbar button will change from gray to color for a connected versa a disconnected device.

Visual Studio 2008 C/C++ Win32 code and exe: [Download not found]

Windows Mobile – tasker2 runs and stops applications periodically

Tasker2 is a tool to launch or kill applications periodically using windows mobile scheduler. It was born to control the running of agent software on windows mobile at specified times. The problem with the agent software was that it does not open/close connections only on usage times but all the time and the device’s battery was drain very fast. We decided to write a helper that would launch and kill the agent to have it running only within a defined time frame.

Background process

We could have written a background process to run external tasks periodically. But the main disadvantage of timers and threads in background processes is that they do not run, if the device is in suspend mode.
To ensure that tasks will be launched also if the device is sleeping, we decided to use the windows mobile scheduler. There are functions inside the notification API to create notifications that will run an application at a specified time. This is what we call a schedule.

The scheduler (notification API)

After a timed schedule has been done by the scheduler, the schedule is removed from the notification database. If you like to have a periodic schedule, you have to ensure that a new schedule is created inside your code.

Pitfalls

During development we found many pitfalls in conjunction with the windows mobile scheduler. This is why I decided to write this post.

The tasks

Tasker2 is a console application without any GUI but it will write a log with all you need to know. Tasker2 supports up to ten tasks. A task is defined using the registry. Every task has an entry for start and stop times, the application to control, an interval for the schedule and a flag for control if a task is only to be run on external power:

REGEDIT4

[HKLM\Software\Tasker\Task1]
"active":DWORD=1
"exe":="\Windows\fexplore.exe"
"arg":="\My Documents"
"start":="1423"
"stop":="1523"
"interval":="2400"
"startOnAConly":DWORD=0;

active: if active is 0, tasker2 will not kill or start the process
exe: name of the process executable to start or kill
arg: arguments to be when launching the executable
start: when to start the executable the next time
stop: when to kill the process the next time
interval: when a start or kill has been executed, tasker2 will create a new schedule using this interval. If the interval is “0010”, the start process will be scheduled for every 10 minutes.
startOnAConly: if 1 and when a process has to be started, the process will only be started if the device is on external power

The scheduler

First, tasker2 is normally only launched one time manually and all future calls are made by the scheduler. Tasker2 will clear and schedule all planned tasks as defined in the registry if it is launched without arguments.

Continue reading ‘Windows Mobile – tasker2 runs and stops applications periodically’ »