Windows Mobile, wince system, starting a CAB file installation with code

Source: Internet
Author: User

Sometimes you need to use code to start the installation cab, and here's the code. Silent installation is not possible.

The user will be prompted to install and the user needs to click on the line.

Using system;using system.collections.generic;using system.text;using system.runtime.interopservices;using System.io;using system.diagnostics;using system.windows.forms;public class bllinstallcab{#region Const private Cons    t int still_active = 0x103;  #endregion #region P/invoke [DllImport ("Coredll.dll", EntryPoint = "CreateProcess", SetLastError = True)] Private static extern bool CreateProcess (string pszimagename, String pszcmdline, IntPtr psaprocess, IntPtr psathread, int finheri    thandles, int fdwcreate, IntPtr pvenvironment, IntPtr pszcurdir, IntPtr psistartinfo, ProcessInfo Pi); [DllImport ("Coredll.dll", SetLastError = True)] private static extern bool GetExitCodeProcess (int hprocess, ref int LpE    Xitcode);        #endregion public sealed class ProcessInfo {public IntPtr hprocess = IntPtr.Zero;        Public IntPtr hthread = IntPtr.Zero;        public int dwprocessid = 0;    public int dwthreadid = 0; }///<summary>//Install multiple cabs in the specified directoryPackage///</summary>//<param name= "Setupdir" >cab package directory path </param> public void Setupfiles (string Setu Pdir) {if (System.IO.Directory.Exists (setupdir) = = True) {processinfo pi = new ProcessInfo ()            ;            DirectoryInfo dirinfo = new DirectoryInfo (setupdir);            fileinfo[] Files = Dirinfo.getfiles ("*.cab"); foreach (FileInfo file in Files) {bool rc = CreateProcess ("Windows\\wceload.exe", "\" "+ file.f                Ullname + "\"/nodelete ", IntPtr.Zero, IntPtr.Zero, 0, 0, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, pi);                int lpexitcode = still_active;                int ErrorCode = 0;                    while (rc = True) && (Lpexitcode = = still_active)) {application.doevents ();                    rc = GetExitCodeProcess (Pi.hProcess.ToInt32 (), ref lpexitcode); if (rc = = true) {IF (Lpexitcode = = still_active) System.Threading.Thread.Sleep (1000);                    } else {ErrorCode = Marshal.GetLastWin32Error ();    }}}}}//<summary>//Check system Install CF version///</summary>  <param name= "Version" > Version </param>//<returns></returns>//private bool HaveNETCF2 (char    Version)//{//RegistryKey netcfkey = null;    Try//{//bool Result = true; Netcfkey = Registry.LocalMachine.OpenSubKey ("software\\microsoft\\.    Netcompactframework ", false);    if (Netcfkey = = null)//return Result;    string[] Valuenames = Netcfkey.getvaluenames ();    if (valuenames = = null)//{//Netcfkey.close ();    return Result; }//for (int i = 0; i < VAluenames.length; i++)//{/////Enumerate registry software\\microsoft\\. NETCOMPACTFRAMEWORK\CF Version Value//if ((valuenames[i]! = null) && (Valuenames[i].    Length > 0) && (valuenames[i][0] = = version)//{//Result = true;    Break    }//else//{//Result = false;    }//}//Return Result;    }//Catch//{//return false;    }//finally//{//if (Netcfkey! = null)//Netcfkey.close (); //    }    //}}

  

Windows Mobile, wince system, starting a CAB file installation with code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.