⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 installer.cs

📁 一个掌上电脑PPC用的汇率转换软件
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Configuration.Install;

using System.Windows.Forms;
using System.Reflection;
using System.IO;
using Microsoft.Win32;
using System.Diagnostics;

namespace InstallerService
{
	[RunInstaller(true)]
	public class Installer : System.Configuration.Install.Installer
	{
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Installer()
		{
			// This call is required by the Windows.Forms Component Designer.
			InitializeComponent();

			// TODO: Add any initialization after the InitComponent call
		}

		/// <summary> 
		/// Required method for Designer support - do not modify 
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			// 
			// Installer
			// 
			this.AfterUninstall += new System.Configuration.Install.InstallEventHandler(this.Installer_AfterUninstall);
			this.AfterInstall += new System.Configuration.Install.InstallEventHandler(this.Installer_AfterInstall);

		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		private void Installer_AfterInstall(object sender, System.Configuration.Install.InstallEventArgs e)
		{
			// get fullpath to .ini file
			string arg = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Setup.ini");
			
			// run WinCE App Manager to install .cab file on device
			RunAppManager(arg);
		}

		private void Installer_AfterUninstall(object sender, System.Configuration.Install.InstallEventArgs e)
		{
			// run app manager in uninstall mode (without any arguments)
			RunAppManager(null);
		}

		private void RunAppManager(string arg)
		{
			// get path to the app manager
			const string RegPath = @"Software\Microsoft\Windows\CurrentVersion\App Paths\CEAppMgr.exe";
			RegistryKey key = Registry.LocalMachine.OpenSubKey(RegPath);					
			string appManager = key.GetValue("") as string;
			
			if (appManager != null)
			{
				// launch the app
				Process.Start(
					string.Format("\"{0}\"", appManager), 
					(arg == null) ? "" : string.Format("\"{0}\"", arg));
			}
			else
			{
				// could not locate app manager
				MessageBox.Show("Could not launch the WinCE Application Manager.");
			}
		}

	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -