简体   繁体   中英

Install/Execute a CAb file[Windows Mobile application file] from C# Code?

I am developing a Windows Mobile application for Framework 6. I want to add functionality to upgrade a patch with the application currently running on a device.

While Windows Mobile application works, it should check asynchronously for any new version available in a server database. If the patch exists, the program should download the .cab (Windows Mobile installer) file and install/run it automatically.

Mainly, I have doubts on these:

  1. How to download a cab file to device's particular folder.
  2. How to install the cab file programmatically. (Programmatically trigger cab file installation without user intervention)

How could it be done?

Please help me on this.....

Downloading a file to local folder generally depends on your repository, ie. you will need slightly different code if you store it on a file share or in lets say web based one. You have to consider option of providing pre-download version check via some sort of manifest file or database record to avoid downloading entire patch just to check its version.

Once you have downloading part sorted (again, depends on storage), you can invoke CAB installation from your app by calling wceload.exe :

            Process proc = Process.Start("wceload.exe", "\"" + Path.Combine(applicationPath, updateFileName) + "\"");
            proc.WaitForExit();

This will however require user to interact and press 'OK' to install new version on top of the old one.

[Edit] Some device manufacturers (like Intermec) provide ways of automatic CAB install on reboot but that's very device-specific so you'd have to read up on this.

I just had to do this, it seems like the install part was answered. If anyone needs the download portion, this worked for me.

 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
        request.Timeout = 10000;
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        Stream receiveStream = response.GetResponseStream();

        using (Stream file = File.OpenWrite("\\Windows\\Desktop\\file.cab"))
        {
            byte[] buffer = new byte[8 * 1024];
            int len;
            while ((len = receiveStream.Read(buffer, 0, buffer.Length)) > 0)
            {
                file.Write(buffer, 0, len);
            }    
        }

I solved this the following way:

  1. Open tcp/ip connection to desktop application.
  2. Send from PDA application the current version number.
  3. During compilation, add to #.inf file version field with value manually (here I could not find solution to do it automatically during compilation).
  4. Desktop application looks up available version in *.inf file and sends it back to PDA application.
  5. PDA application receives it and compares with running version.
  6. If version on dektop computer is higher than running version, PDA application sends request to deliver CAB file on desktop computer (here can be dialog introduced for requesting cab file).
  7. Desktop computer sends CAB file to PDA application.
  8. PDA application receives CAB file and stores it locally.
  9. Then run installation by wceload.exe with parameters /delete 1 /silent "full path of cab file"
  10. In case succesful installation, exit application or restart PDA.
  11. If PDA application has

It is not a few strings of code, however it works perfectly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM