{"id":229,"date":"2009-10-12T23:13:34","date_gmt":"2009-10-12T17:43:34","guid":{"rendered":"http:\/\/techtwaddle.net\/?p=229"},"modified":"2011-04-12T23:13:54","modified_gmt":"2011-04-12T17:43:54","slug":"applications-getting-device-information-embedded-exe-rapi-and-more","status":"publish","type":"post","link":"https:\/\/techtwaddle.co.in\/blog\/2009\/10\/12\/applications-getting-device-information-embedded-exe-rapi-and-more\/","title":{"rendered":"Applications: Getting device information (embedded exe, rapi and more)"},"content":{"rendered":"<div style=\"text-align: justify;\"><span style=\"font-family: Comic Sans MS;\">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:<\/span><\/div>\n<p>&nbsp;<\/p>\n<div style=\"text-align: justify;\"><span style=\"font-family: Comic Sans MS;\">1) Create a PC app which gets all the information using RAPI api&#8217;s and displays it.<\/span><\/div>\n<p>&nbsp;<\/p>\n<div style=\"text-align: justify;\"><span style=\"font-family: Comic Sans MS;\">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&#8217;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&#8217;s, all device API&#8217;s are at your disposal.<\/span><\/div>\n<p>&nbsp;<\/p>\n<div style=\"text-align: justify;\"><span style=\"font-family: Comic Sans MS;\">3) Create a PC app which uses the <a href=\"geekswithblogs.net\/TechTwaddle\/archive\/2009\/10\/16\/how-to-embed-an-exe-inside-another-exe-as-a.aspx\">embedded exe approach<\/a>. This is a bit loony but works (; And yes, this is what I used in my app.<\/span><\/div>\n<p>&nbsp;<\/p>\n<div style=\"text-align: justify;\"><span style=\"font-family: Comic Sans MS;\">Let me digress here for people who do not know about <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/bb737283.aspx\">RapiConfig.exe<\/a>. RapiConfig is tool that ships with the Windows Mobile SDK&#8217;s and can be used to test out CSP&#8217;s (Configuration Service Provider) by using provisioning XML&#8217;s. RapiConfig works over Active Sync. So basically you run this tool from command line like:<\/span><\/div>\n<p><br style=\"font-family: Comic Sans MS;\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">C:\\&gt;RapiConfig \/P config.xml<\/span><br style=\"font-family: Comic Sans MS;\" \/><br \/>\n<br style=\"font-family: Comic Sans MS;\" \/><br \/>\n<span style=\"font-family: Comic Sans MS;\">This command has the same effect as calling <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/bb158518.aspx\"><span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">DMProcessConfigXML()<\/span><\/a> API on the device with config.xml&#8217;s contents.<\/span><\/p>\n<div style=\"text-align: justify;\"><span style=\"font-family: Comic Sans MS;\">And then I came across the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/bb737683.aspx\">DeviceInformation CSP<\/a>. 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&#8217;t go into that. So you give this service provider an XML like this:<\/span><\/div>\n<p><br style=\"font-family: Comic Sans MS;\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&lt;wap-provisioningdoc&gt;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &lt;characteristic type=&quot;DeviceInformation&quot;&gt;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &lt;parm-query name=&quot;OperatingSystem&quot; \/&gt; <\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &lt;parm-query name=&quot;OperatingSystemVersion&quot; \/&gt; <\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &lt;parm-query name=&quot;Product&quot; \/&gt; <\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &lt;parm-query name=&quot;ProductVersion&quot; \/&gt; <\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &lt;\/characteristic&gt;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&lt;\/wap-provisioningdoc&gt;<\/span><br style=\"font-family: Comic Sans MS;\" \/><br \/>\n<br style=\"font-family: Comic Sans MS;\" \/><br \/>\n<span style=\"font-family: Comic Sans MS;\">and it spits out the response like this:<\/span><br style=\"font-family: Comic Sans MS;\" \/><br \/>\n<br style=\"font-family: Comic Sans MS;\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&lt;wap-provisioningdoc&gt;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &lt;characteristic type=&quot;DeviceInformation&quot;&gt;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;parm name=&quot;OperatingSystem&quot; value=&quot;Microsoft Windows CE&quot;\/&gt;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;parm name=&quot;OperatingSystemVersion&quot; value=&quot;Version 5.2 (Build 1235)&quot;\/&gt;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;parm name=&quot;Product&quot; value=&quot;Windows Mobile&reg; 6 Standard&quot;\/&gt;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;parm name=&quot;ProductVersion&quot; value=&quot;CE OS 5.2.1235 (Build 17740.0.2.0)&quot;\/&gt;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &lt;\/characteristic&gt;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&lt;\/wap-provisioningdoc&gt;<\/span><\/p>\n<div style=\"text-align: justify;\"><span style=\"font-family: Comic Sans MS;\">So while developing this application I thought I could use some of RapiConfig. I shouldn&#8217;t have to write everything from scratch. I&#8217;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&#8217;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 <a href=\"geekswithblogs.net\/TechTwaddle\/archive\/2009\/10\/16\/how-to-embed-an-exe-inside-another-exe-as-a.aspx\">previous post<\/a>.<\/span><\/div>\n<p>&nbsp;<\/p>\n<div style=\"text-align: justify;\"><span style=\"font-family: Comic Sans MS;\">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 <span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">RapiConfigOut.xml<\/span> in the same directory. The application opens this output xml, parses it and displays the information to the user.<\/span><\/div>\n<p>&nbsp;<\/p>\n<div style=\"text-align: justify;\"><span style=\"font-family: Comic Sans MS;\">If no device is connected then RapiConfig keeps waiting for the device to connect. To prevent this I used a few RAPI api&#8217;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 &quot;Please make sure the device is connected.. blah bla&quot;<\/span><\/div>\n<p><br style=\"font-family: Comic Sans MS;\" \/><br \/>\n<span style=\"font-family: Comic Sans MS;\">A few points worth jotting down<\/span><br style=\"font-family: Comic Sans MS;\" \/><br \/>\n<br style=\"font-family: Comic Sans MS;\" \/><br \/>\n<span style=\"font-family: Comic Sans MS;\">(*) After extracting the RapiConfig exe, I was calling <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms682425(VS.85).aspx\"><span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">CreateProcess()<\/span><\/a> on it to launch it:<\/span><br style=\"font-family: Comic Sans MS;\" \/><br \/>\n<br style=\"font-family: Comic Sans MS;\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">wsprintf(lpCmdLine, L&quot;\/P %s&quot;, XML_FILENAME);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">ret = CreateProcess(EXE_FILENAME, lpCmdLine, NULL, NULL, TRUE, 0, NULL, NULL, &amp;sui, &amp;pi);<\/span><\/p>\n<div style=\"text-align: justify;\"><span style=\"font-family: Comic Sans MS;\">But this didn&#8217;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 <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms682425(VS.85).aspx\"><span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">CreateProcess()<\/span><\/a> mentioned that the first parameter to it maybe be <span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">NULL<\/span>, in that case <span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">lpCmdLine<\/span> parameter should include the exe name. And when I gave this a try, it worked! So now you call <span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">CreateProcess()<\/span> like below:<\/span><\/div>\n<p><br style=\"font-family: Comic Sans MS;\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">wsprintf(lpCmdLine, L&quot;%s \/P %s&quot;, EXE_FILENAME, XML_FILENAME);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">ret = CreateProcess(NULL, lpCmdLine, NULL, NULL, FALSE, 0, NULL, NULL, &amp;sui, &amp;pi);<\/span><br style=\"font-family: Comic Sans MS;\" \/>\n<\/p>\n<div style=\"text-align: justify;\"><span style=\"font-family: Comic Sans MS;\">(*) Some while back I had tried to fiddle with <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa920274.aspx\">RAPI<\/a>. I had tried to launch an exe on device remotely from the PC. But it didn&#8217;t work. Turns out I was calling <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa922061.aspx\"><span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">CeRapiInit()<\/span><\/a> incorrectly. I was calling it directly, not on any object but actually you need to call it on the <span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">IRapiSession<\/span> interface. I should really be reading the documentation carefully before jumping to the code (;<\/span><\/div>\n<p><br style=\"font-family: Comic Sans MS;\" \/><br \/>\n<br style=\"font-family: Comic Sans MS;\" \/><br \/>\n<span style=\"font-family: Comic Sans MS;\">Here are a few snapshots of the application, this is with craddled emulator.<\/span><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"456\" height=\"538\" alt=\"\" src=\"\/images\/geekswithblogs_net\/TechTwaddle\/DeviceInformation\/DevInfo_startScreen.JPG\" \/><\/p>\n<p>\n<img decoding=\"async\" loading=\"lazy\" width=\"615\" height=\"542\" alt=\"\" src=\"\/images\/geekswithblogs_net\/TechTwaddle\/DeviceInformation\/DevInfo_error.JPG\" \/><\/p>\n<p>\n<img decoding=\"async\" loading=\"lazy\" width=\"458\" height=\"540\" alt=\"\" src=\"\/images\/geekswithblogs_net\/TechTwaddle\/DeviceInformation\/DevInfo_info1.JPG\" \/><\/p>\n<p>\n<img decoding=\"async\" loading=\"lazy\" width=\"457\" height=\"538\" alt=\"\" src=\"\/images\/geekswithblogs_net\/TechTwaddle\/DeviceInformation\/DevInfo_info2.JPG\" \/>\n<\/p>\n<div style=\"text-align: justify;\"><span style=\"font-family: Comic Sans MS;\">Oh and the DeviceInformation doesn&#8217;t give you the resolution of the device. I used <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa918985.aspx\">CeGetSystemMetrics()<\/a> to get that part of information. And if there is any other details that you would want on this app, please leave a comment.<\/span><\/div>\n<p>\n<span style=\"font-family: Comic Sans MS;\">Good day!<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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: &nbsp; 1) Create a PC app which gets all the information using RAPI api&#8217;s &hellip; <a href=\"https:\/\/techtwaddle.co.in\/blog\/2009\/10\/12\/applications-getting-device-information-embedded-exe-rapi-and-more\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Applications: Getting device information (embedded exe, rapi and more)<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false},"categories":[1],"tags":[],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p1ktFF-3H","_links":{"self":[{"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/posts\/229"}],"collection":[{"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/comments?post=229"}],"version-history":[{"count":1,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/posts\/229\/revisions"}],"predecessor-version":[{"id":230,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/posts\/229\/revisions\/230"}],"wp:attachment":[{"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/media?parent=229"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/categories?post=229"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/tags?post=229"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}