Geeks With Blogs
Tex-blog Mobile and other stuff
Recently I needed to execute an application on my Windows CE device from my laptop, I spent some time on google searching for some program to do that, but I have not found anything that worked for me. Because such aplication is not a big effort, I decided to write it and share with community. Below is source code for it and link to binary.

#include <windows.h>
#include <rapi.h>
#include <stdio.h>
#pragma comment(lib, "rapi.lib")

int main(int argc, char* argv[]) {
  if ( argc == 1 ) {
    printf("Executes process on Windows Ce device over ActiveSync\n\n");
    printf("cerun apppath [commands]\n\n");
    printf("  apppath\tPath to aplication ie.: \\windows\\clock.exe\n");
    printf("  commands\tOptionally any number of parameters\n\n");
    return 1;
  }

  // Rapi init.
  RAPIINIT ri = { sizeof(RAPIINIT) };
  if (CeRapiInitEx(&ri) != NOERROR || ri.hrRapiInit == E_FAIL) {
    printf("ActiveSync connection is required\n");
    return 1;
  }
 
int res = WaitForSingleObject(ri.heRapiInit, 5000);
  if (res == WAIT_OBJECT_0 && ri.hrRapiInit != NOERROR || res == WAIT_TIMEOUT) {
    printf("Failed making connection\n");
    return 1;
 
}

  // App name.
  WCHAR szApp[MAX_PATH]={0};
  mbstowcs(szApp, argv[1], MAX_PATH);

  // Commands.
  WCHAR szCmd[MAX_PATH]={0};
  WCHAR szCmdTmp[MAX_PATH]={0};
  for ( int i = 2; i < argc; ++i ) {
    mbstowcs(szCmdTmp, argv[i], MAX_PATH);
    wcscat(szCmd, szCmdTmp);
    wcscat(szCmd, L" ");
  }

  // Execution.
  CeCreateProcess(szApp, szCmd, 0, 0, 0, 0, 0, 0, 0, 0);
 
CeRapiUninit();
  return 0;
}

To compile it you will need to install Pocket PC 2003 SDK, it comes with RAPI library. Other SDK-s should provide this library too, but Iam not sure about it. To inform your compiler about location of rapi.lib and rapi.h, add path folders which on my system are as follows:

"C:\Program Files\Windows CE Tools\wce420\POCKET PC 2003\Activesync\Lib"
"C:\Program Files\Windows CE Tools\wce420\POCKET PC 2003\Activesync\Inc"

link to binary: http://strony.aster.pl/marcinj/prg/wince/cerun.exe
An example of execution from command line:  "cerun.exe cprog.exe -url tel: 123456789", will open Phone Application and call 123456789 number. Posted on Wednesday, February 6, 2008 6:47 PM | Back to top


Comments on this post: CeRun - run application on Pocket PC from desktop PC

# re: CeRun - run application on Pocket PC from desktop PC
Requesting Gravatar...
Thanks

-http://www.25rupiah.co.cc-
Left by aknutman on Feb 26, 2009 6:33 AM

Your comment:
 (will show your gravatar)


Copyright © Martinez | Powered by: GeeksWithBlogs.net