Windows Mobile – A simple web server with extended features

The attached web server offers some options to control the device or show informations about it. The web server runs on the device and enables direct control or delivers information about the device.

The project enclosed default web page offers all implemented commands. The following is a list of what is currently implemented:

  • SystemInfo: get OS version info
  • BEEP: let the device beep
  • START: starts a process
  • KILL: kills a process
  • SETLED: light/unlight/blink a LED
  • VIBRATE: special LED case, this sets a LED which is a placeholder for the vibrate motor
  • SIP: show/hide the Software Keyboard
  • SHOW: ShowWindow implementation (show normal, hide, minimize etc)
  • ENABLEWINDOW: enable or disable a window

The default web page


If you click a function (command) the output is displayed at the bottom of the example default page:

You can also call the functions directly from any web browser that has access to the devices network and get only the answer back.

In example, calling “” will give you “‘SystemInfo’ ”, ‘Microsoft Windows CE 5.2.29040’ = OK” or so.

Reflection instead of switch() or If/ElseIf

These commands can be easily extended as the code uses reflection to look up the commands you send. This is a better approach than doing a If/ElseIf or Switch() serach for known commands:

        /// <summary>
        /// here the myCommands object is queried for the recognized command
        /// </summary>
        /// <param name="sFunc">name of the command</param>
        /// <param name="sArg">arguments to the command</param>
        /// <param name="sResponse">return string of a command</param>
        /// <returns>True if existing command was found</returns>
        public static bool execCmd(string sFunc, string sArg, ref string sResponse)
            bool bRet = true;
                // Instantiate this class
                myCommands cmbn = new myCommands(sFunc, sArg);

                // Get the desired method by name: DisplayName
                //MethodInfo methodInfo = typeof(CallMethodByName).GetMethod("DisplayName");
                MethodInfo methodInfo = typeof(myCommands).GetMethod(sFunc);

                // Use the instance to call the method without arguments
                methodInfo.Invoke(cmbn, null);
                sResponse = cmbn.response;
            catch (Exception ex)
                System.Diagnostics.Debug.WriteLine("Exception in execCmd for '" + sFunc + "' and '" + sArg + "' " + ex.Message); 
                bRet = false; 
            return bRet;

The myCommands class looks like this and is easy to extend:

        /// <summary>
        /// this class holds all know commands
        /// the class is queried using reflection to lookup a command
        /// </summary>
        class myCommands

            string name;
            string arg="";
            public string response="";

            public myCommands(string name, string sArg)
       = name;
                this.arg = sArg;

            /// <summary>
            /// return some System information
            /// </summary>
            public void SystemInfo()
                string sOS = System.Environment.OSVersion.ToString();                
                response = sOS;

            public void BEEP()
                beepType beep = (beepType)Enum.Parse(typeof(beepType), arg, false);

So, if you need to add an command, simply add a new function inside myCommands class using arg and response to communicate with the web server.

Code and binary

The Visual Studio 2008 source code is written against  Compact Framwork 2.0. There are two projects, one is the great CompactWeb web server and the other is the webCommand project. The webCommand project includes a directory inetpub, which is deployed below the applications directory.

inetpub Directory

    • default.html
      this is the default web site containg examples for all commands


<script language="javascript" type="text/javascript" src="ahah.js"></script>
<script language="javascript" type="text/javascript">
//Calls the library function 'ahah' - defined in 'ahah.js' file.
function load(filename) {
<p>WebCommands TestPage</p>
<ul id="SystemInfo">
 <li><a href="javascript:load('ahah.html?SystemInfo');">OS Version</a></li>
  • javascript.js
    simply loads ahah.js and implements the load function (asynchronously call (AJAX) technology).
  • ahah.js
    this javascript library does asynchronously call the ‘web commands’ (AJAX).

The rest of the files are included for testing. The same is valid for the server dir, which contains example files which will work on an external web server (ie XAMPP on windows), if cross-side scripting is allowed. The server files contain fixed IP address for the device and have to be changed if you would like to test cross-side scripting.

I insist on your fantasy, what elese is possible. Some examples: get a screenshot, get extended device informations, get a process list…….

[Download not found]

Leave a Reply