windows mobile ,wince 系统,用代码启动cab文件安装
有时候需要用代码来启动安装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文件安装的更多相关文章
- windows下制作linux U盘启动盘或者安装优盘(转)
windows下制作linux U盘启动盘或者安装优盘(转) Linux发行版排行榜:http://iso.linuxquestions.org/ [方案一]:UltraISO(不推荐,在Window ...
- ros 使用python代码启动launch文件
在开发中我们经常会遇到使用python代码启动launch文件这样的问题.一般的做法是使用subprocess调用roslaunch.但是这种方法使用起来并不方便.要涉及到自己去控制进程的状态.由于r ...
- Windows 8.1 系统上用Oracle VM VirtualBox 安装windows 2008 R2 SP1 的虚拟机 出现 Error Code: 0x000000C4
Windows 8.1 本来可以安装Hyper-v来安装虚拟机,但是我现在需要使用Oracle VM VirtualBox来安装虚拟机, 所以必须先卸载Hyper-v VirtualBox 安装的虚拟 ...
- linux deepin 12.12.1和Windows 7双系统修改默认启动项
1.打开终端,输入 sudo gedit /etc/default/grub ,然后输入密码.2.在出来的文本编辑器中找到 GRUB_DEFAULT=0 一行,把0改为2(因为我的Windows 7在 ...
- windows下给用非exe格式的文件安装网卡驱动
之前我只知道用驱动精灵来给新机器装网卡驱动,或者用下载好的exe格式文件给非新机器装网卡驱动. 今天下载了一个非exe格式的文件,就不知道怎么装了,百度了一下才知道,可以通过:”设备管理器“-> ...
- Win10下windows mobile设备中心连接不上的方法无法启动
微软Win10自动更细补丁后windows mobile设备中心就无法启动了 需要重新启动相关的服务并授予 本机登录用户 权限 1.点击屏幕左下角“开始”图标,点击“运行”,在弹出的输入框中输入“se ...
- 使用Visual Studio 2008创建你的第一个Windows Mobile程序介绍
使用Visual Studio 2008创建你的第一个Windows Mobile程序介绍 Windows MobileMobileWindowsMicrosoftWinForm 介绍 Microso ...
- Windows Mobile入门
转自 http://www.cnblogs.com/peterzb/archive/2009/05/12/1455256.html [准备篇] 最近安排做手机视频监控方面开发,这个对我来 ...
- 安装 Linux 与 Windows 10 双系统,你需要了解的一切
该选Windows 10还是Linux Mint?鱼与熊掌当然可以兼得,但咱们得掌握点小技巧才能顺利搞定. Windows 10绝不是唯一一款值得我们安装在自己计算机之上的免费操作系统.Linux只靠 ...
随机推荐
- xcconfig
[xcconfig] 1.When you can use a .xcconfig file? Use .xcconfig files if you find yourself changing th ...
- 整理悬浮在列表中a元素时改变a元素上下边框颜色的问题。
整理一下当悬浮在a元素上时a的上下边颜色改变,并且里面的内容不会移动,下面是PSD图效果区域: 刚开始我先给A元素加了上下边框和颜色,利用a:hover改变a元素上下的边框颜色,但是第一个a元素的下边 ...
- 看图说说Heap中对象的生存状态
- (转)C# .net微信开发,开发认证,关注触发消息,自动应答,事件响应,自定义菜单
原文地址:http://www.cnblogs.com/qidian10/p/3492751.html 成为开发者 string[] ArrTmp = { "token", Req ...
- Navicet Mysql数据库电脑本地备份
Navicet Mysql数据库电脑本地备份 1.打开navicat客户端,连上mysql后,双击左边你想要备份的数据库.点击"计划",再点击"新建批处理作业" ...
- linux 流量统计
因为很多vps或者服务器都是限流量的,但是又很多服务商并没有提供详细的流量表,比如每天的流量表,所以肯定有人很想知道自己服务器到底跑了多少流量. vnstat就是一个很好用的服务器流量统计命令.我截几 ...
- C# winform无边框窗体移动
public partial class MessageHints : Form { //窗体移动API [DllImport("user32.dll")] public stat ...
- Python验证实现登陆功能以及用户锁定(文件存储)
废话不多说先交代码(只是一个简单的验证):#!/usr/bin/env python #-*- coding:utf8 -*- # Structured program ‘#’是注释 # Functi ...
- cesium编程入门(五)绘制形状
通过Entity添加形状 先来看一个添加立方体的例子 var viewer = new Cesium.Viewer('cesiumContainer'); var redBox = **viewer. ...
- 微信小店调用api代码示例
刚开始调用微信小店api的时候,可能大家会遇到问题.系统总是提示system error,归根结底还是发送的参数不正确. 下面给出几个调用例子: 例子写得不全. <?php function c ...