Name "Serial"
OutFile "Serial.exe"
## Include headers
!include MUI.nsh
!include LogicLib.nsh
## Pages
!insertmacro MUI_PAGE_WELCOME
Page custom SerialPageShow SerialPageLeave
;!define MUI_PAGE_CUSTOMFUNCTION_SHOW ComponentsPageShow
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_INSTFILES
## Languages
!insertmacro MUI_LANGUAGE English
## Displays the serial dialog
Function SerialPageShow
!insertmacro MUI_HEADER_TEXT "Enter Serial Code" "Enter the software serial code to continue."
PassDialog::Dialog Serial \
/HEADINGTEXT 'Please enter the serial code located on the software CD case...' \
/CENTER \
/BOXDASH 12 70 4 '' \
/BOXDASH 92 70 4 '' \
/BOXDASH 172 70 4 '' \
/BOXDASH 252 70 4 '' \
/BOX 332 70 4 ''
Pop $R0 # success, back, cancel or error
FunctionEnd
## Validate serial numbers
Function SerialPageLeave
## Pop values from stack
Pop $R0
Pop $R1
Pop $R2
Pop $R3
Pop $R4
Banner::show "Please Wait....Your Serial Number is Validating..."
## A bit of validation
;StrCpy '$5' '$R0-$R1-$R2-$R3-$R4'
StrCpy '$5' '$R0-$R1-$R2-$R3-$R4$\r$\n'
StrCpy $6 0
Loop:
IntOp $6 $6 + 1
StrCmp $6 500 Bad ;1 more than the # serials in file
Push $6 ;line number to read from
File /oname=$PLUGINSDIRserial.txt "c:\serial.txt"
Push "$PLUGINSDIR\serial.txt" ;text file to read
Call ReadFileLine
Pop $0 ;output string (read from file.txt)
StrCmp $0 $5 Good
Goto Loop
Bad:
Banner::destroy
MessageBox MB_OK|MB_ICONEXCLAMATION "The entered username or password is incorrect!"
Delete "$PLUGINSDIR\serial.txt"
Abort
Good:
Delete "$PLUGINSDIR\serial.txt"
FunctionEnd
Function ReadFileLine
Exch $0 ;file
Exch
Exch $1 ;line number
Push $2
Push $3
FileOpen $2 $0 r
StrCpy $3 0
Loop:
IntOp $3 $3 + 1
ClearErrors
FileRead $2 $0
IfErrors +2
StrCmp $3 $1 0 loop
FileClose $2
Pop $3
Pop $2
Pop $1
Exch $0
FunctionEnd
## Just a dummy section
Section 'A section'
SectionEnd Pass Daialog - problem with serial.txt
I use this code to create new install program with serial window. I read many topic on the forum and in the site wiki and don't know how (i'm not programmer) must create file with serials to compare values (install program and serial.txt). Please help me 🙂