windows mobile ,wince 系統,用代碼啟動cab檔案安裝

來源:互聯網
上載者:User

標籤:void   tco   system   dllimport   point   machine   .net   mars   curd   

有時候需要用代碼來啟動安裝cab,以下是代碼。不能實現靜默安裝。

啟動後會提示使用者是否安裝,需要使用者點擊是才行。

 

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 const 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 fInheritHandles, int fdwCreate, IntPtr pvEnvironment, IntPtr pszCurDir, IntPtr psiStartInfo, ProcessInfo pi);    [DllImport("coredll.dll", SetLastError = true)]    private static extern bool GetExitCodeProcess(int hProcess, ref int lpExitCode);    #endregion    public sealed class ProcessInfo    {        public IntPtr hProcess = IntPtr.Zero;        public IntPtr hThread = IntPtr.Zero;        public int dwProcessID = 0;        public int dwThreadID = 0;    }    /// <summary>    /// 安裝指定目錄下多Cab包    /// </summary>    /// <param name="SetupDir">Cab包目錄路徑</param>    public void SetupFiles(string SetupDir)    {        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.FullName + "\" /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>    /// 檢查系統安裝CF版本    /// </summary>    /// <param name="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++)    //        {    //            //枚舉註冊表Software\\Microsoft\\.NETCompactFramework\CF版本值    //            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 系統,用代碼啟動cab檔案安裝

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.