Applications: Getting device information (embedded exe, rapi and more)

I was working on this application which runs on the PC and gets information about the windows mobile device which is connected to the PC over active sync. Now there are a couple of ways in which you can do this:

 

1) Create a PC app which gets all the information using RAPI api’s and displays it.

 

2) Create two binaries, one for the PC and one for the WinMob device. The PC app launches the WinMob app remotely using RAPI API’s, the WinMob app runs and writes all the information it can gather into a file on the device. The PC app then remotely reads this file and displays it to the user. The let down is that you need to create/maintain two binaries but the advantage is that you are not limited to the RAPI api’s, all device API’s are at your disposal.

 

3) Create a PC app which uses the embedded exe approach. This is a bit loony but works (; And yes, this is what I used in my app.

 

Let me digress here for people who do not know about RapiConfig.exe. RapiConfig is tool that ships with the Windows Mobile SDK’s and can be used to test out CSP’s (Configuration Service Provider) by using provisioning XML’s. RapiConfig works over Active Sync. So basically you run this tool from command line like:



C:\>RapiConfig /P config.xml



This command has the same effect as calling DMProcessConfigXML() API on the device with config.xml’s contents.

And then I came across the DeviceInformation CSP. The DeviceInformation service provider, as the name gives it away, provides information about the device and it can also be used to set information but we won’t go into that. So you give this service provider an XML like this:



<wap-provisioningdoc>

    <characteristic type="DeviceInformation">

       <parm-query name="OperatingSystem" />

       <parm-query name="OperatingSystemVersion" />

       <parm-query name="Product" />

       <parm-query name="ProductVersion" />

    </characteristic>

</wap-provisioningdoc>



and it spits out the response like this:



<wap-provisioningdoc>

    <characteristic type="DeviceInformation">

        <parm name="OperatingSystem" value="Microsoft Windows CE"/>

        <parm name="OperatingSystemVersion" value="Version 5.2 (Build 1235)"/>

        <parm name="Product" value="Windows Mobile® 6 Standard"/>

        <parm name="ProductVersion" value="CE OS 5.2.1235 (Build 17740.0.2.0)"/>

    </characteristic>

</wap-provisioningdoc>

So while developing this application I thought I could use some of RapiConfig. I shouldn’t have to write everything from scratch. I’ll just find out the SDK installation directory on the PC somehow, run this tool with my xml, parse the output xml and display it. But wait, what if the PC does not have the SDK installed. This simple application can’t depend on that. And that is when I had this crazy idea of embedding RapiConfig.exe within my application (; I wrote up a small test app to find out if this approach would even work. It did. You can get the details here in my previous post.

 

So thats the way it works. The application first extracts the embedded RapiConfig exe and the xml file into the current directory where the app is running from. Then it runs RapiConfig passing it the extracted xml. After RapiConfig completes executing and terminates, it creates a RapiConfigOut.xml in the same directory. The application opens this output xml, parses it and displays the information to the user.

 

If no device is connected then RapiConfig keeps waiting for the device to connect. To prevent this I used a few RAPI api’s in my application to find out if a device is connected using Active Sync, and only if it is, I launch RapiConfig exe. Otherwise, I display a message saying "Please make sure the device is connected.. blah bla"



A few points worth jotting down



(*) After extracting the RapiConfig exe, I was calling CreateProcess() on it to launch it:



wsprintf(lpCmdLine, L"/P %s", XML_FILENAME);

ret = CreateProcess(EXE_FILENAME, lpCmdLine, NULL, NULL, TRUE, 0, NULL, NULL, &sui, &pi);

But this didn’t work for me. The output XML was the exact same as the input xml, without any data. Launching the same extracted exe from command line worked! How was this possible? I tried a couple of things with SECURITY_ATTRIBUTES, inheriting handles etc but none worked. The documentation for CreateProcess() mentioned that the first parameter to it maybe be NULL, in that case lpCmdLine parameter should include the exe name. And when I gave this a try, it worked! So now you call CreateProcess() like below:



wsprintf(lpCmdLine, L"%s /P %s", EXE_FILENAME, XML_FILENAME);

ret = CreateProcess(NULL, lpCmdLine, NULL, NULL, FALSE, 0, NULL, NULL, &sui, &pi);

(*) Some while back I had tried to fiddle with RAPI. I had tried to launch an exe on device remotely from the PC. But it didn’t work. Turns out I was calling CeRapiInit() incorrectly. I was calling it directly, not on any object but actually you need to call it on the IRapiSession interface. I should really be reading the documentation carefully before jumping to the code (;





Here are a few snapshots of the application, this is with craddled emulator.

Oh and the DeviceInformation doesn’t give you the resolution of the device. I used CeGetSystemMetrics() to get that part of information. And if there is any other details that you would want on this app, please leave a comment.

Good day!

Leave a Reply

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