• 在设备后台安装CAB而不让用户发觉


     前引:

    有些应用程序(在PC上运行,比如掌智手机助手)在一开始运行的时候需要把CAB程序自动拷贝到设备上然后安装;或者在设备上有某一程序,它的运行需要依托某个Framework(打包为CAB程序),那么就需要运行该Framework CAB程序(注意:涉及到非特权签名或特权签名)。可是,我们并不想让用户知道我们安装了这个程序(注:很多用户很讨厌按照提示操作安装CAB程序),因此就会考虑如何才能在后台悄悄的安装CAB文件呢?

     Wceload Tool

    MS为我们提供Wceload Tool,
    格式如下:
    wceload [ /noaskdest | /askdest ] [ /delete <number> | /noui | /nouninstall ] <cab file location>

    详细内容和参数描述参见 MSDN Wceload Tool

     参考

     在网上找到了这么一段话,发现用处甚大,具体谁写的就不知道了。先借用下。 


    首先你要检查CAB是否能正确安装。 
    What kind of platform are you running on? If it's a WM 5.0 or Smartphone device. Use:
     

    wceload.exe "cabfile.cab" /silent 

    /noask /noui is for Pocket PC 2003 and older....Notice that "silent" is in placed in the end....


    还有,可以参考这篇How to install CAB file silently by \Windows\wceload.exe on Wince.NET 4.2?

    里面的一位博友也说了一段话“This is code that we use on Windows Mobile 5 and PocketPC2003.  I have not tried this on WindowsCE 4.2 but would guess that WM5 way would be best.  We experienced similar pain trying to get this to work on WM5 as many posts mix the parameters between the different mobile platforms.”,他提供了一段代码,具体的就不贴了,可以看上面的原帖。

    可以看出上面的2段话都同时指出了在Windows mobile不同版本上要注意Wceload参数的不同。第一段话已经很明白的指出了。 

     实现 

    下面是我写的函数,在Windows mobile 6 Professional Emulator , Pocket PC 2003 Emulator和 Sony Ericsson X1 XPERIA 真机上测试通过。


            // for WM5 and later
            public static bool RunCABSliently(string cabPath, int waitMillSeconds)
            
    {
                
    if (!File.Exists(cabPath))
                    
    return false;

                
    string parm = @"/delete 0 """ + cabPath + @""" /silent";
                
    try
                
    {
                    ProcessStartInfo psi 
    = new ProcessStartInfo(@"\Windows\wceload.exe", parm);
                    Process p 
    = new Process();
                    p.StartInfo 
    = psi;
                    
    bool res = p.Start();
                    
    if (!res)
                        
    return false;

                    
    if (waitMillSeconds > 0)
                        p.WaitForExit(waitMillSeconds);
                    
    else
                        p.WaitForExit();
                    
                    
    if (p.ExitCode != 0)
                        
    return false;
                }

                
    catch
                
    {
                    
    return false;
                }


                
    return true;
            }



            // for Pocket PC 2003
            public static bool RunCABSliently(string cabPath, int waitMillSeconds)
            
    {
                
    if (!File.Exists(cabPath))
                    
    return false;

                
    string parm = @"/noaskdest /noui """ + cabPath + @"""";

                
    try
                
    {
                    ProcessStartInfo psi 
    = new ProcessStartInfo(@"\Windows\wceload.exe", parm);
                    Process p 
    = new Process();
                    p.StartInfo 
    = psi;
                    
    bool res = p.Start();
                    
    if (!res)
                        
    return false;

                    
    if (waitMillSeconds > 0)
                        p.WaitForExit(waitMillSeconds);
                    
    else
                        p.WaitForExit();

                    
    if (p.ExitCode != 0)
                        
    return false;
                }

                
    catch
                
    {
                    
    return false;
                }


                
    return true;
            }

    其实两个函数是在传入参数上有所不同,其余的都一样。

    可能又有一些朋友要问, PC上的程序在运行时怎样才能在设备后台安装CAB文件,这里提供一种思路,不过前提是你的ActiveSync已经连接了:封装一个dll文件,该dll中包含一个接口,该接口负责启动你的CAB程序(如上面的代码,只需要加上具体的CAB路径就可以了)。在PC程序运行时,通过RAPI将该dllCAB文件传送到设备上,然后通过CeRapiInvoke调用dll上的接口就可以了。


     
     
     
     

    --------------------------------------------------

    李森 – listen
    E-mail:  lisencool@gmail.com

    声明:
    这里集中了在WinCEWindows Mobile开发中的一些基本常识。我很乐意和大家分享,也希望大家提出意见,并给我投稿,我会第一时间替您发表并署上您的大名!

    Announce:
    Here collects general knowledge on WinCE and Windows mobile. I 'm very glad to share them with all friends, and also hope you can share your problems and opinions and contribute articles to me to share with others. I'll publish your articles and sign your name at the first time.

      
  • 相关阅读:
    leetcode二叉树相同的树
    leetcode二叉树中序遍历
    leetcode二叉树前序遍历
    leetcode数组中级Lc287.寻找重复数
    概要设计说明书
    leetcode二叉树对称二叉树
    小数点处理详解:切舍、切上、四舍五入
    C++多态的两种使用方式
    让Ogre的资源管理器为我们服务
    地形纹理Splatting技术(翻译)
  • 原文地址:https://www.cnblogs.com/Lisen/p/1588509.html
Copyright © 2020-2023  润新知