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只靠 ...
随机推荐
- 20155209 2016-2017-2 《Java程序设计》第七周学习总结
20155209 2016-2017-2 <Java程序设计>第七周学习总结 教材学习内容总结 认识时间与日期 时间的度量 GMT(Greenwich Mean Time) 时间:现在不是 ...
- windows-x64 php5.6+apache2.4+mysql配置
随手一记, 方便以后查找! 1.安装apache2.4 - 下载压缩文件并解压到 D:\Develop\Apache24 - 修改 conf 目录下: httpd.conf 文件 - 服务器目录: ...
- 如何在centos环境下搭建java环境
在CentOS上安装Java环境:[1]使用yum安装java 现阶段做企业级项目开发一般都采用Java语言.开发的项目需要放在服务器上运行测试,若以CentOS系统为服务器系统,首先要解决就是Cen ...
- mfc的一点总结-----Edit Control操作
获取Edit Control(编辑框)的内容: CString key; GetDlgItem(IDC_EDIT1)->GetWindowText(key); 其中IDC_EDIT1是所要获取编 ...
- Appium常用API(二)
接前面的常用API(一),本文接着介绍如下: 1.press_keycode press_keycode(self, keycode, metastate=None): Sends a keycode ...
- oracle树形语句
oracle树查询的最重要的就是select…start with…connect by…prior语法了.依托于该语法,我们可以将一个表形结构的以树的顺序列出来.在下面列述了oracle中树型查询的 ...
- PPI协议(西门子PLCS7-200)
西门子PLC S7-200 PPI协议报文,9600,偶校验,8数据位,1停止位 读取vb100寄存器:PC发送报文68 1B 1B 68 2 0 6C 32 1 0 0 0 0 0 E 0 0 4 ...
- IIS 8 nodejs + iisnode 配置
最近再Server 2012 + IIS 8 中配置NodeJS 运行环境,具体配置过程就不细说了(随便搜搜一堆),安装完nodejs 和 iisnode 之后,出现一个报错,如下: The iisn ...
- python实现注册登录小程序
用python 实现模拟注册和登录的程序:用户信息最终以字典的格式储存在一个txt文件里,具体实现如下: users.txt里用户字典格式如下: { '}, '}, '} } # 注册 f = ope ...
- androidstudio提示adb错误:cannot parse version string:kg01的解决方法
打开adb.exe的文件目录,同时按下shift和鼠标右键,打开cmd后运行一下这个命令adb kill-server