我想通过IP文本框和密钥文本框传递外部.exe参数。
这是我的安装代码。外部.exe接收三个参数。
第一个是产品名称,第二个是IP,第三个是密钥。
您不知道如何编写nsis来传递外部参数。
使用方法令人困惑。
在代码下(Setup.nsi)
## input lincesekey, ip
Function PageInputLicenseInfo
ReserveFile "pageInputLicenseInfo.ini"
!insertmacro MUI_INSTALLOPTIONS_EXTRACT "pageInputLicenseInfo.ini"
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "pageInputLicenseInfo.ini"
FunctionEnd
## I want to pass external .exe parameters
Function MyCustomLicense
#IP
!insertmacro MUI_INSTALLOPTIONS_READ $R0 "pageInputLicenseInfo.ini" "Field 3" "State"
${If} $R0 == "1"
Exec '"$INSTDIR\JCertFileGenerator.exe "/${PRODUCT_NAME},$R0""'
${EndIf}
#KEY
!insertmacro MUI_INSTALLOPTIONS_READ $R1 "pageInputLicenseInfo.ini" "Field 4" "State"
${If} $R1 == "1"
Exec '"$INSTDIR\JCertFileGenerator.exe "/${PRODUCT_NAME},$R0,$R1""'
${EndIf}
## external .exe
!insertmacro MUI_INSTALLOPTIONS_READ $R2 "pageInputLicenseInfo.ini" "Field 5" "State"
${If} $R2 == "1"
File "..\ADAgent\bin\Release\JCertFileGenerator.exe"
Exec '"$INSTDIR\JCertFileGenerator.exe "/${PRODUCT_NAME},$R0,$R1""'
${EndIf}
FunctionEnd
在代码下(pageInputLicenseInfo.ini)
Ini file generated by the HM NIS Edit IO designer.
[Settings]
NumFields=5
[Field 1]
Type=Label
Text=IP
Left=6
Right=37
Top=8
Bottom=19
[Field 2]
Type=Label
Text=License Key
Left=5
Right=64
Top=24
Bottom=35
[Field 3]
Type=Text
Left=65
Right=274
Top=4
Bottom=16
State=1
[Field 4]
Type=Text
Left=65
Right=274
Top=20
Bottom=33
State=1
[Field 5]
Type=Button
Text=확인
Flags=NOTIFY
Left=225
Right=275
Top=40
Bottom=56
State=1
如果您编写一种使用字段3、4、5将参数传递到外部.exe的方法,我将不胜感激。
答案 0 :(得分:0)
您的命令行引号错误,并且您也无法在某些代码路径中提取JCertFileGenerator.exe!
报价应如下所示:
Exec '"c:\my path\program.exe" param1 "param with spaces" /param3'
这是一个愚蠢的例子:
Unicode True
!define PRODUCT_NAME "Hello World"
Name "${PRODUCT_NAME}"
OutFile Test.exe
!include MUI.nsh
!include LogicLib.nsh
!include InstallOptions.nsh
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
Page Custom LicensekeyPageCreate LicensekeyPageNotify
!insertmacro MUI_LANGUAGE English
Function .onInit
; I'm writing the .ini directly here because this is just an example
InitPluginsDir
FileOpen $0 "$PluginsDir\pageInputLicenseInfo.ini" a
FileWriteUTF16LE /BOM $0 ""
FileClose $0
WriteIniStr "$PluginsDir\pageInputLicenseInfo.ini" "Settings" NumFields 5
WriteIniStr "$PluginsDir\pageInputLicenseInfo.ini" "Field 1" Type Label
WriteIniStr "$PluginsDir\pageInputLicenseInfo.ini" "Field 1" Text IP
WriteIniStr "$PluginsDir\pageInputLicenseInfo.ini" "Field 1" Left 6
WriteIniStr "$PluginsDir\pageInputLicenseInfo.ini" "Field 1" Right 37
WriteIniStr "$PluginsDir\pageInputLicenseInfo.ini" "Field 1" Top 8
WriteIniStr "$PluginsDir\pageInputLicenseInfo.ini" "Field 1" Bottom 19
WriteIniStr "$PluginsDir\pageInputLicenseInfo.ini" "Field 2" Type Label
WriteIniStr "$PluginsDir\pageInputLicenseInfo.ini" "Field 2" Text "License Key"
WriteIniStr "$PluginsDir\pageInputLicenseInfo.ini" "Field 2" Left 5
WriteIniStr "$PluginsDir\pageInputLicenseInfo.ini" "Field 2" Right 64
WriteIniStr "$PluginsDir\pageInputLicenseInfo.ini" "Field 2" Top 24
WriteIniStr "$PluginsDir\pageInputLicenseInfo.ini" "Field 2" Bottom 35
WriteIniStr "$PluginsDir\pageInputLicenseInfo.ini" "Field 3" Type Text
WriteIniStr "$PluginsDir\pageInputLicenseInfo.ini" "Field 3" Left 65
WriteIniStr "$PluginsDir\pageInputLicenseInfo.ini" "Field 3" Right 274
WriteIniStr "$PluginsDir\pageInputLicenseInfo.ini" "Field 3" Top 4
WriteIniStr "$PluginsDir\pageInputLicenseInfo.ini" "Field 3" Bottom 16
WriteIniStr "$PluginsDir\pageInputLicenseInfo.ini" "Field 3" State 1
WriteIniStr "$PluginsDir\pageInputLicenseInfo.ini" "Field 4" Type Text
WriteIniStr "$PluginsDir\pageInputLicenseInfo.ini" "Field 4" Left 65
WriteIniStr "$PluginsDir\pageInputLicenseInfo.ini" "Field 4" Right 274
WriteIniStr "$PluginsDir\pageInputLicenseInfo.ini" "Field 4" Top 20
WriteIniStr "$PluginsDir\pageInputLicenseInfo.ini" "Field 4" Bottom 33
WriteIniStr "$PluginsDir\pageInputLicenseInfo.ini" "Field 4" State 1
WriteIniStr "$PluginsDir\pageInputLicenseInfo.ini" "Field 5" Type Button
WriteIniStr "$PluginsDir\pageInputLicenseInfo.ini" "Field 5" Text "${U+d655}${U+c778}"
WriteIniStr "$PluginsDir\pageInputLicenseInfo.ini" "Field 5" Flags NOTIFY
WriteIniStr "$PluginsDir\pageInputLicenseInfo.ini" "Field 5" Left 225
WriteIniStr "$PluginsDir\pageInputLicenseInfo.ini" "Field 5" Right 275
WriteIniStr "$PluginsDir\pageInputLicenseInfo.ini" "Field 5" Top 40
WriteIniStr "$PluginsDir\pageInputLicenseInfo.ini" "Field 5" Bottom 56
WriteIniStr "$PluginsDir\pageInputLicenseInfo.ini" "Field 5" State 1
FunctionEnd
Function LicenseKeyPageCreate
!insertmacro INSTALLOPTIONS_DISPLAY "pageInputLicenseInfo.ini"
FunctionEnd
Function LicensekeyPageNotify
!insertmacro INSTALLOPTIONS_READ $0 "pageInputLicenseInfo.ini" "Settings" "State"
${If} $0 = 5 ; Was the button clicked?
!insertmacro MUI_INSTALLOPTIONS_READ $R0 "pageInputLicenseInfo.ini" "Field 3" "State"
!insertmacro MUI_INSTALLOPTIONS_READ $R1 "pageInputLicenseInfo.ini" "Field 4" "State"
ExecWait '"cmd.exe" /C echo "${PRODUCT_NAME}" IP=$R0 Key="$R1" &pause'
Abort ; Stay on the current page
${EndIf}
FunctionEnd
在进入InstFiles页面之前在$ InstDir中执行某些操作通常不是一个好主意,您可能想使用$ PluginsDir或在InstFiles页面之后询问许可证密钥信息。