杉宫竹苑工作室

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 739|回复: 0

NSIS一键安装打印机

[复制链接]
发表于 2022-7-25 15:33:49 | 显示全部楼层 |阅读模式

正式会员享受无限制浏览网站功能和高速网盘下载,赶快加入本站吧!

您需要 登录 才可以下载或查看,没有账号?立即注册

x
AutoInstallPrinter.ini 文件说明
  1. [PrinterInfo]
  2. ; 网络打印机的IP地址,如192.168.3.250
  3. IP=
  4. ; 当前目录下打印机的驱动文件,如16L\oemsetup.inf
  5. PrinterDrivePath=
  6. ; 打印机驱动的名称,在inf文件中找,如上面的oemsetup.inf里的PCL6 Driver for Universal Print
  7. DrvName=
  8. ; 自定义在控制面板显示的名称,如16楼打印机室
  9. CustomizePrinterName=
复制代码
  1. !define HAVE_UPX
  2. !ifdef HAVE_UPX
  3. !packhdr tmp.dat "upx -9 tmp.dat"
  4. !endif

  5. ; ------ MUI 现代界面定义 (1.67 版本以上兼容) ------
  6. !include "MUI.nsh"
  7. !include "x64.nsh"
  8. !include "logiclib.nsh"
  9. !include "Printer.nsh"
  10. ; MUI 预定义常量
  11. !define MUI_ABORTWARNING
  12. !define MUI_ICON "Printer.ico"
  13. !define PRODUCT_NAME "进化论自动安装打印机工具"
  14. !define PRODUCT_VERSION "2022.01.10.16"
  15. ; 安装界面包含的语言设置
  16. !insertmacro MUI_LANGUAGE "SimpChinese"

  17. Var WINDOWS_Language ;WINDOWS语言
  18. Var PrinterIp ;打印机的IP地址
  19. Var PrinterDrivePath ;打印机驱动路径
  20. Var CustomizePrinterName ;自定义打印机名称
  21. Var DrvName ;打印机驱动名称
  22. ; 载入插件
  23. !define pluginDir ".\plugins"
  24. !addplugindir "${pluginDir}"

  25. ;文件版本声明
  26. VIProductVersion ${PRODUCT_VERSION}
  27. VIAddVersionKey /LANG=2052 "ProductName" "进化论自动安装打印机工具"
  28. VIAddVersionKey /LANG=2052 "Comments" "永恒心锁"
  29. VIAddVersionKey /LANG=2052 "CompanyName" "http://www.yhxs3344.net"
  30. VIAddVersionKey /LANG=2052 "LegalTrademarks" "http://www.yhxs3344.net"
  31. VIAddVersionKey /LANG=2052 "LegalCopyright" "永恒心锁"
  32. VIAddVersionKey /LANG=2052 "FileDescription" "进化论自动安装打印机工具"
  33. VIAddVersionKey /LANG=2052 "FileVersion" ${PRODUCT_VERSION}

  34. ; 检测程序是否已运行
  35. !macro CheckRunningPrograms
  36. System::Call 'kernel32::CreateMutexA(i 0, i 0, t"${PRODUCT_NAME}") i .r1 ?e'
  37. Pop $R0
  38. ${If} $R0 <> 0
  39. Messagebox MB_TOPMOST|MB_ICONINFORMATION|MB_OK "安装程序已经在运行,请不要多次打开程序"
  40. Quit
  41. ${EndIf}
  42. !macroend

  43. XPStyle on
  44. OutFile "AutoInstallPrinter.exe"
  45. Caption "进化论自动安装打印机工具"

  46. RequestExecutionLevel admin ;管理员权限

  47. Section
  48. Sectionend

  49. SilentInstall silent

  50. Function .onInit
  51. !insertmacro CheckRunningPrograms ;安装程序运行检测的变量
  52. InitPluginsDir
  53. File /oname=$PLUGINSDIR\vbs.reg ".\nsPlugin\vbs.reg"
  54. ClearErrors
  55. ReadINIStr $PrinterIp "$EXEDIR\AutoInstallPrinter.ini" "PrinterInfo" "IP"
  56. ReadINIStr $PrinterDrivePath "$EXEDIR\AutoInstallPrinter.ini" "PrinterInfo" "PrinterDrivePath"
  57. ReadINIStr $DrvName "$EXEDIR\AutoInstallPrinter.ini" "PrinterInfo" "DrvName"
  58. ReadINIStr $CustomizePrinterName "$EXEDIR\AutoInstallPrinter.ini" "PrinterInfo" "CustomizePrinterName"
  59. ReadRegStr $WINDOWS_Language HKLM "SYSTEM\CurrentControlSet\Control\Nls\Language" "Default"
  60. ${If} $PrinterIp = ""
  61. ${AndIf} $PrinterDrivePath = ""
  62. ${AndIf} $DrvName = ""
  63. ${AndIf} $CustomizePrinterName = ""
  64. Messagebox MB_TOPMOST|MB_ICONINFORMATION|MB_OK "配置信息有缺失,请查看AutoInstallPrinter.ini文件"
  65. ExecWait '"$WINDIR\System32\notepad.exe" $EXEDIR\AutoInstallPrinter.ini'
  66. Quit
  67. ${EndIf}

  68. ${If} ${RunningX64}
  69. Call OSX64
  70. ${Else}
  71. Call OSX86
  72. ${EndIf}
  73. FunctionEnd

  74. Function OSX86
  75. nsExec::ExecToLog '"cmd" /c "$WINDIR\regedit.exe /s" "$PLUGINSDIR\vbs.reg"'
  76. ${If} $WINDOWS_Language = 0804
  77. nsExec::ExecToLog '"cmd" /c "cscript $WINDIR\System32\Printing_Admin_Scripts\zh-cn\Prnport.vbs" -a -r $PrinterIp -h $PrinterIp -o raw -me -y public -n 9100'
  78. Sleep 300
  79. ExecWait 'rundll32 printui.dll,PrintUIEntry /if /b "$CustomizePrinterName" /f "$EXEDIR\$PrinterDrivePath" /r "$PrinterIp" /m "$DrvName"'
  80. Sleep 1000
  81. Messagebox MB_TOPMOST|MB_ICONINFORMATION|MB_OK "打印机安装完成"
  82. nsExec::ExecToLog '"cmd" /c "explorer shell:::{A8A91A66-3A7D-4424-8D24-04E180695C7A}"'
  83. ${EndIf}

  84. ${If} $WINDOWS_Language == 0409
  85. nsExec::ExecToLog '"cmd" /c "cscript $WINDIR\System32\Printing_Admin_Scripts\en-US\Prnport.vbs" -a -r $PrinterIp -h $PrinterIp -o raw -me -y public -n 9100'
  86. Sleep 300
  87. ExecWait 'rundll32 printui.dll,PrintUIEntry /if /b "$CustomizePrinterName" /f "$EXEDIR\$PrinterDrivePath" /r "$PrinterIp" /m "$DrvName"'
  88. Sleep 1000
  89. Messagebox MB_TOPMOST|MB_ICONINFORMATION|MB_OK "打印机安装完成"
  90. nsExec::ExecToLog '"cmd" /c "explorer shell:::{A8A91A66-3A7D-4424-8D24-04E180695C7A}"'
  91. ${EndIf}
  92. FunctionEnd

  93. Function OSX64
  94. # 关闭重定向
  95. System::Call "Kernel32::Wow64EnableWow64FsRedirection(i 0)"
  96. #修改VBS默认
  97. nsExec::ExecToLog '"cmd" /c "$WINDIR\regedit.exe /s" "$PLUGINSDIR\vbs.reg"'

  98. ${If} $WINDOWS_Language = 0804
  99. nsExec::ExecToLog '"cmd" /c "cscript $WINDIR\SysWOW64\Printing_Admin_Scripts\zh-cn\Prnport.vbs" -a -r $PrinterIp -h $PrinterIp -o raw -me -y public -n 9100'
  100. Sleep 300
  101. ExecWait 'rundll32 printui.dll,PrintUIEntry /if /b "$CustomizePrinterName" /f "$EXEDIR\$PrinterDrivePath" /r "$PrinterIp" /m "$DrvName"'
  102. Sleep 1000
  103. Messagebox MB_TOPMOST|MB_ICONINFORMATION|MB_OK "打印机安装完成"
  104. nsExec::ExecToLog '"cmd" /c "explorer shell:::{A8A91A66-3A7D-4424-8D24-04E180695C7A}"'
  105. ${EndIf}

  106. ${If} $WINDOWS_Language == 0409
  107. nsExec::ExecToLog '"cmd" /c "cscript $WINDIR\SysWOW64\Printing_Admin_Scripts\en-US\Prnport.vbs" -a -r $PrinterIp -h $PrinterIp -o raw -me -y public -n 9100'
  108. Sleep 300
  109. ExecWait 'rundll32 printui.dll,PrintUIEntry /if /b "$CustomizePrinterName" /f "$EXEDIR\$PrinterDrivePath" /r "$PrinterIp" /m "$DrvName"'
  110. Sleep 1000
  111. Messagebox MB_TOPMOST|MB_ICONINFORMATION|MB_OK "打印机安装完成"
  112. nsExec::ExecToLog '"cmd" /c "explorer shell:::{A8A91A66-3A7D-4424-8D24-04E180695C7A}"'
  113. ${EndIf}

  114. # 恢复重定向
  115. System::Call "Kernel32::Wow64EnableWow64FsRedirection(i 1)"
  116. FunctionEnd
复制代码












回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|SgzyStudio

GMT+8, 2024-4-30 08:34 , Processed in 0.107000 second(s), 18 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表