有时候需要用代码来启动安装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. 14 Finding a Shared Motif

    Problem A common substring of a collection of strings is a substring of every member of the collecti ...

  2. 怎样才能做好SNS社区网站

    顺应历史潮流,大批的网络社区SNS(Social Networking Services)发展起来. SNS旨在构建一个网络上的人际关系网,让公众足不出户即可实现社交意愿.SNS满足了人的交流欲望,成 ...

  3. BZOJ 1001 狼抓兔子 (最小割转化成最短路)

    1001: [BeiJing2006]狼抓兔子 Time Limit: 15 Sec  Memory Limit: 162 MBSubmit: 27715  Solved: 7134[Submit][ ...

  4. Linux的进程与服务(一)

    启动的配置文件/etc/inittab,修改完配置文件以后 init q立即生效 # Default runlevel. The runlevels used by RHS are: # - halt ...

  5. PHP性能分析工具:xhprof

    ​phpize的安装   一直想装VLD却一直没装上,因为需要用到phpize,但这个工具大部分机子都没有装,上网搜了一下大部分都是讲phpize的应用没有讲怎么安装. 今天终于搜到了,不过是要在li ...

  6. 组队作业_One

    Part 1.前言 结对项目作业 结对同学高裕翔的博客 本博文pdf版本 Part 2.PSP表 PSP3.1 Personal Software Process Stages 预估耗时(分钟) 实际 ...

  7. delphi中,write和read的用法?什么时候需要用?

    如你所说,在控件或者类的属性中,read 表示 读取,write 则表示设置.比如在类中:TTestClass = (Class)privateFOrderCode:String;publicprop ...

  8. pro1

    #include<iostream> using namespace std; int main(void) { int i,a[],sum; cin>>i; for(i=0; ...

  9. SQL SERVER 查找锁信息

    通过系统的存储过程  sp_who 或 sp_who2 可以查找出所有的锁信息, 但是看不出是哪个表, 什么语句 当使用 sp_who 或 sp_who2 查找锁信息的时候, 有个 spid 信息,  ...

  10. (zxing.net)一维码UPC A的简介、实现与解码

    一.简介 UPC(Universal Product Code)码是最早大规模应用的条码,其特性是一种长度固定.连续性的条  码,目前主要在美国和加拿大使用,由于其应用范围广泛,故又被称万用条码. U ...