1. 程式人生 > >nsis接收命令列引數,實現動態安裝

nsis接收命令列引數,實現動態安裝

功能:通過接收外部exe傳入的引數,實現動態安裝對應的安裝包,以及動態設定安裝路徑

額外說明:外部傳入的引數是通過命令列引數的方式傳入的

作者:weekdawn

; Script generated by the HM NIS Edit Script Wizard.  
var str4500
var str4501
var str4700
var strProductName

!include "logiclib.nsh"
!include "FileFunc.nsh"

Name "DC系列"
OutFile "Setup.exe"

SilentInstall silent
AutoCloseWindow true
ShowInstDetails nevershow

Section "MainSection" SEC01
  #通過命令列設定需要安裝的產品名稱和安裝路徑
  push $R0
  push $R1
  push $R2
  #獲取命令列引數,形式:-product=“DC-4501” -path="D:\TEMP"
  ${Getparameters} $R0
  #解析引數資料
  ${GetOptions} $R0 "-Product=" $R1
  ${GetOptions} $R0 "-Path=" $R2
  pop $R0
  #設定安裝路徑
  StrCpy $INSTDIR "$R2"
  SetOutPath "$INSTDIR"
  SetOverwrite ifnewer
  File "D:\NsisPackage\公共檔案.txt"
  
  StrCpy $strProductName $R1
  ${if} $R1 == $str4500
  File /r  "D:\NsisPackage\DC-4500"
  ${elseif} $R1 == $str4501
  File /r "D:\NsisPackage\DC-4501"
  ${elseif} $R1 == $str4700
  File /r "D:\NsisPackage\DC-4700"
  ${endif}
  pop $R1
  pop $R2
SectionEnd

Function .onInit
  Call SetString
Functionend

Function SetString
	StrCpy  $str4500 "DC-4500"
	StrCpy  $str4501 "DC-4501"
	StrCpy  $str4700 "DC-4700"
FunctionEnd