using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Configuration.Install; using System.Diagnostics; using System.Linq; using System.Threading.Tasks; namespace HXX.Scanner.Install { [RunInstaller(true)] public partial class Installer : System.Configuration.Install.Installer { public Installer() { InitializeComponent(); this.AfterInstall += Installer_AfterInstall; } private void Installer_AfterInstall(object sender, InstallEventArgs e) { //获取用户设定的安装目标路径, 注意,需要在Setup项目里面自定义操作的属性栏里面的CustomActionData添加上/targetdir="[TARGETDIR]\" //注意写入注册表时:HXXScannerClient.exe 不能出现更多的“.”否则无法写入 string path = this.Context.Parameters["targetdir"]; string[] commands = new string[4]; commands[0] = "/c" + " reg add HKCR\\scannerClient /f /ve /d \"URL:scannerClient\" "; commands[1] = "/c" + " reg add HKCR\\scannerClient /f /v \"URL Protocol\" /d \"\" "; commands[2] = "/c" + " reg add HKCR\\scannerClient\\shell /f /ve /d \"open\" "; commands[3] = "/c" + " reg add HKCR\\scannerClient\\shell\\open\\command /f /ve /d \"\\\"" + path.Replace("'","") + "\\" + "HXXScannerClient.exe\\\" \\\"%1\\\"\" "; foreach (var command in commands) { Process p = new Process { StartInfo = { FileName = "cmd.exe", Arguments = command, UseShellExecute = false, RedirectStandardInput = true, RedirectStandardOutput = true, CreateNoWindow = true } }; p.Start(); p.StandardInput.WriteLine("exit"); p.Close(); } //string path = "C:\\Program Files (x86)\\HXX\\scannerClient\\"; //RegistryKey key = Registry.ClassesRoot; //RegistryKey software = key.CreateSubKey("scannerClient"); //software = key.OpenSubKey("scannerClient", true); //software.SetValue("", "scannerClientProtocol"); ////software = key.OpenSubKey("scannerClient", true); //software.SetValue("URL Protocol", ""); //software = key.CreateSubKey("scannerClient\\DefaultIcon"); //software = key.OpenSubKey("scannerClient\\DefaultIcon", true); //software.SetValue("", path + "HXXScannerClient.exe,1"); //software = key.CreateSubKey("scannerClient\\shell\\Open\\command"); //software = key.OpenSubKey("scannerClient\\shell\\Open\\command", true); //software.SetValue("", "\"" + path + "HXXScannerClient.exe\",\"1\""); //key.Close(); } } }