有时候需要用代码来启动安装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文件安装的更多相关文章

  1. windows下制作linux U盘启动盘或者安装优盘(转)

    windows下制作linux U盘启动盘或者安装优盘(转) Linux发行版排行榜:http://iso.linuxquestions.org/ [方案一]:UltraISO(不推荐,在Window ...

  2. ros 使用python代码启动launch文件

    在开发中我们经常会遇到使用python代码启动launch文件这样的问题.一般的做法是使用subprocess调用roslaunch.但是这种方法使用起来并不方便.要涉及到自己去控制进程的状态.由于r ...

  3. Windows 8.1 系统上用Oracle VM VirtualBox 安装windows 2008 R2 SP1 的虚拟机 出现 Error Code: 0x000000C4

    Windows 8.1 本来可以安装Hyper-v来安装虚拟机,但是我现在需要使用Oracle VM VirtualBox来安装虚拟机, 所以必须先卸载Hyper-v VirtualBox 安装的虚拟 ...

  4. linux deepin 12.12.1和Windows 7双系统修改默认启动项

    1.打开终端,输入 sudo gedit /etc/default/grub ,然后输入密码.2.在出来的文本编辑器中找到 GRUB_DEFAULT=0 一行,把0改为2(因为我的Windows 7在 ...

  5. windows下给用非exe格式的文件安装网卡驱动

    之前我只知道用驱动精灵来给新机器装网卡驱动,或者用下载好的exe格式文件给非新机器装网卡驱动. 今天下载了一个非exe格式的文件,就不知道怎么装了,百度了一下才知道,可以通过:”设备管理器“-> ...

  6. Win10下windows mobile设备中心连接不上的方法无法启动

    微软Win10自动更细补丁后windows mobile设备中心就无法启动了 需要重新启动相关的服务并授予 本机登录用户 权限 1.点击屏幕左下角“开始”图标,点击“运行”,在弹出的输入框中输入“se ...

  7. 使用Visual Studio 2008创建你的第一个Windows Mobile程序介绍

    使用Visual Studio 2008创建你的第一个Windows Mobile程序介绍 Windows MobileMobileWindowsMicrosoftWinForm 介绍 Microso ...

  8. Windows Mobile入门

    转自 http://www.cnblogs.com/peterzb/archive/2009/05/12/1455256.html [准备篇]        最近安排做手机视频监控方面开发,这个对我来 ...

  9. 安装 Linux 与 Windows 10 双系统,你需要了解的一切

    该选Windows 10还是Linux Mint?鱼与熊掌当然可以兼得,但咱们得掌握点小技巧才能顺利搞定. Windows 10绝不是唯一一款值得我们安装在自己计算机之上的免费操作系统.Linux只靠 ...

随机推荐

  1. centos7 单台zookeeper安装

    1.创建 /usr/local/services/zookeeper 文件夹:  mkdir -p /usr/local/services/zookeeper 2.进入到 /usr/local/ser ...

  2. redis centos 上以 tar.gz 安装redis

    1.下载安装文件#wget http://download.redis.io/releases/redis-3.2.3.tar.gz 2.删除文件 rm -rf /usr/local/redisrm ...

  3. C++中break/Continue,exit/return的理解

    刚才遇到了一个问题,大概是这样的. func1执行完成,进入func1Complete,其中switch处理func1返回的数据,如果返回数据是clear则重新执行func1. 测试的时候发现func ...

  4. CentOS 6.0下phpvod搭建教程(LAMP+phpvod)

    之所以安装CentOS是因为之前试过RedHat,但是发现RedHat在安装时,无法获取安装源,原因是RedHat系统没有在RHN注册. 网上的很多教程都说可以直接换用CentOS的源,可我小搞里一会 ...

  5. Oracle E-Business Suite并发处理机制(Current Processing)

    2012年写过一篇关于Oracle E-Business Suite并发管理器的文章,回头看之前总结的内容还是比较单薄,很多点没说到,最近在看这块的内容,索性再写一篇稍微完整的文章来. Oracle ...

  6. REQUEST的TRACE文件

    --REQUEST的TRACE文件 SELECT    'Trace Name: '       || DEST.VALUE       || '/'       || LOWER (DBNM.VAL ...

  7. 8.使用Exists监控ZNode的三大Change事件

    一. zookeeper是一个分布式的协调程序(所有程序都是通过订阅它来相互感知)   1. tcp(长链接) + watcher server ->client client ->ser ...

  8. androidstudio提示adb错误:cannot parse version string:kg01的解决方法

    打开adb.exe的文件目录,同时按下shift和鼠标右键,打开cmd后运行一下这个命令adb kill-server

  9. Linux下.Net Core+Nginx环境搭建小白教程

    前言 对于接触.Net Core的我们来说之前从未接触过Linux,出于资源和性能及成本的考虑我们可能要将我们的环境搬到Linux下,这对于我们从未接触过Linux的童鞋们来说很棘手,那么我今天将带你 ...

  10. SQL 判断数据库是否有相关表 字段

    --判断数据库是否有相关表 if exists (select 1 from sysobjects where id = object_id(' 表名 ') and type = ' U ' ); - ...