Installer.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Configuration.Install;
  6. using System.Diagnostics;
  7. using System.Linq;
  8. using System.Threading.Tasks;
  9. namespace HXX.Scanner.Install
  10. {
  11. [RunInstaller(true)]
  12. public partial class Installer : System.Configuration.Install.Installer
  13. {
  14. public Installer()
  15. {
  16. InitializeComponent();
  17. this.AfterInstall += Installer_AfterInstall;
  18. }
  19. private void Installer_AfterInstall(object sender, InstallEventArgs e)
  20. {
  21. //获取用户设定的安装目标路径, 注意,需要在Setup项目里面自定义操作的属性栏里面的CustomActionData添加上/targetdir="[TARGETDIR]\"
  22. //注意写入注册表时:HXXScannerClient.exe 不能出现更多的“.”否则无法写入
  23. string path = this.Context.Parameters["targetdir"];
  24. string[] commands = new string[4];
  25. commands[0] = "/c" + " reg add HKCR\\scannerClient /f /ve /d \"URL:scannerClient\" ";
  26. commands[1] = "/c" + " reg add HKCR\\scannerClient /f /v \"URL Protocol\" /d \"\" ";
  27. commands[2] = "/c" + " reg add HKCR\\scannerClient\\shell /f /ve /d \"open\" ";
  28. commands[3] = "/c" + " reg add HKCR\\scannerClient\\shell\\open\\command /f /ve /d \"\\\"" + path.Replace("'","") + "\\" + "HXXScannerClient.exe\\\" \\\"%1\\\"\" ";
  29. foreach (var command in commands)
  30. {
  31. Process p = new Process
  32. {
  33. StartInfo =
  34. {
  35. FileName = "cmd.exe",
  36. Arguments = command,
  37. UseShellExecute = false,
  38. RedirectStandardInput = true,
  39. RedirectStandardOutput = true,
  40. CreateNoWindow = true
  41. }
  42. };
  43. p.Start();
  44. p.StandardInput.WriteLine("exit");
  45. p.Close();
  46. }
  47. //string path = "C:\\Program Files (x86)\\HXX\\scannerClient\\";
  48. //RegistryKey key = Registry.ClassesRoot;
  49. //RegistryKey software = key.CreateSubKey("scannerClient");
  50. //software = key.OpenSubKey("scannerClient", true);
  51. //software.SetValue("", "scannerClientProtocol");
  52. ////software = key.OpenSubKey("scannerClient", true);
  53. //software.SetValue("URL Protocol", "");
  54. //software = key.CreateSubKey("scannerClient\\DefaultIcon");
  55. //software = key.OpenSubKey("scannerClient\\DefaultIcon", true);
  56. //software.SetValue("", path + "HXXScannerClient.exe,1");
  57. //software = key.CreateSubKey("scannerClient\\shell\\Open\\command");
  58. //software = key.OpenSubKey("scannerClient\\shell\\Open\\command", true);
  59. //software.SetValue("", "\"" + path + "HXXScannerClient.exe\",\"1\"");
  60. //key.Close();
  61. }
  62. }
  63. }