Archive: need help regarding the installer with serialkey check


need help regarding the installer with serialkey check
Hai,

With some knowledge , i tried an approach of building installer with with 3 steps in process.

first, checking for the active internet connection and will abort the process without connection.

secondly,checking the ip address of the client system to be within the required IP address range.On success need to move to serialkey check.

Here user needs to enter the given serial key and will check over the server after posting the key.But for time being only comparing locally.Installer is working until IP address check and the serial keycheck is not working. Please help me out


I am posting the code below:

; MUI 1.67 compatible ------
!include MUI.nsh
!include LogicLib.nsh
!include defines.nsh
!include sampleIP.nsh

; MUI Settings
!define MUI_ABORTWARNING
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\orange-install.ico"
;!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"
XPStyle on

; Reserve files
ReserveFile "validateSerial.ini"
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS

;pages

; Welcome page
!insertmacro MUI_PAGE_WELCOME
Page custom SerialPageShow SerialPageLeave
Page custom validateSerial
; Instfiles page
!insertmacro MUI_PAGE_INSTFILES
; Finish page
!insertmacro MUI_PAGE_FINISH


; Language files
!insertmacro MUI_LANGUAGE "English"


; MUI end ------

Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "AppDeploy.exe"
InstallDir "$DESKTOP"
ShowInstDetails show

Function .onInit

call ConnectInternet

FunctionEnd



Section -InstallerSettings
SetOutPath "$INSTDIR"
SetOverwrite ifnewer
Call SetMarquee
SectionEnd



Function ConnectInternet

Push $R0

ClearErrors
Dialer::AttemptConnect
IfErrors noie3

Pop $R0
StrCmp $R0 "online" connected
MessageBox MB_OK|MB_ICONSTOP "Cannot connect to the internet."
Quit ;This will quit the installer.
;You might want to add your own error handling.

noie3:

; IE3 not installed
MessageBox MB_OK|MB_ICONINFORMATION \
"Please connect to the internet now."

connected:

Pop $R0

FunctionEnd

Function SetMarquee
FindWindow $0 "#32770" "" $HWNDPARENT
GetDlgItem $0 $0 1004
System::Call user32::GetWindowLong(ir0,i-16)i.r1
IntOp $1 $1 | 8 # PBS_MARQUEE
System::Call user32::SetWindowLong(ir0,i-16,ir1)
IntOp $1 ${WM_USER} + 10
SendMessage $0 $1 1 200 $2
FunctionEnd


Section -IPCheck
Internet::GetLocalHostIP ${VAR_1}
push $1
call ValidateIP
${If} ${Errors}
MessageBox MB_OK|MB_ICONINFORMATION "Your IP address: $1 and INVAILD"
Quit
${Else}
MessageBox MB_OK|MB_ICONINFORMATION "IP Address is vaild and will continue with installation process"
!insertmacro MUI_INSTALLOPTIONS_EXTRACT "validateSerial.ini"
Call SerialPageShow

${EndIf}

SectionEnd

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

Function SerialPageLeave

## Pop values from stack
Pop $R1
Pop $R2
Pop $R3
Pop $R4
Pop $R5

;!insertmacro MUI_HEADER_TEXT "Validating..." "Please Wait"
;!insertmacro MUI_INSTALLOPTIONS_DISPLAY "validateSerial.ini"

;MessageBox MB_OK "Break1"

FunctionEnd


Function ValidateSerial

StrCmp $R1 '1BH6' +3
MessageBox MB_OK|MB_ICONEXCLAMATION "Please enter vaild serial number!"
Abort

StrCmp $R2 '2Y6M0' +3
MessageBox MB_OK|MB_ICONEXCLAMATION "Please enter vaild serial number!"
Abort

StrCmp $R3 'SL5H' +3
MessageBox MB_OK|MB_ICONEXCLAMATION "Please enter vaild serial number!"
Abort

StrCmp $R4 'MSU6' +3
MessageBox MB_OK|MB_ICONEXCLAMATION "Please enter vaild serial number!"
Abort

StrCmp $R5 'U1M3' SerialOK
MessageBox MB_OK|MB_ICONEXCLAMATION " Please enter vaild serial number!"
Abort
SerialOK:
FunctionEnd


Section -Prerequisites

SetOutPath $INSTDIR
MessageBox MB_YESNO "Install the python open source package?" /SD IDYES IDNO endNetCF
File "python.msi"
ExecWait '"msiexec" /i "$INSTDIR\python.msi"'
endNetCF:

SectionEnd


You can't have Call SerialPageShow in there.
To skip the PassDialog page, call Abort in it's show function.

Stu


Hello Stu,

I had removed the call serial page from that section. Here the problem is that the installer is that starting with IPcheck and directly going on with installation process.

I need to go serialkey check after the success of IP Check only. On success of serialCheck installation process should start.Will those functions need to be called from any other sections?

thanks,


Like I said, to skip a custom page call Abort in it's show function. You cannot call these functions yourself, but only let NSIS call them using the Page instruction.

Stu


Hello Stu,

Thanks alot..i changed the code and got minor problem where the order of checking is changed.

As i said first want to check with internet connection check and IP range from which needs to go for serialkey check.But installer starts with serial keycheck and on success of check going for IP check followed by installation.

changed code is below:

!include MUI.nsh
!include LogicLib.nsh
!include defines.nsh
!include sampleIP.nsh

; MUI Settings
!define MUI_ABORTWARNING
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\orange-install.ico"
;!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"
XPStyle on

;pages

; Welcome page
!insertmacro MUI_PAGE_WELCOME
#Custom pages
Page custom SerialPageShow SerialPageLeave
; Instfiles page
!insertmacro MUI_PAGE_INSTFILES
; Finish page
!insertmacro MUI_PAGE_FINISH
; Language files
!insertmacro MUI_LANGUAGE "English"
; MUI end ------

Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "AppDeploy.exe"
InstallDir "$DESKTOP"
ShowInstDetails show

Function .onInit

call ConnectInternet

FunctionEnd

Section -SETTINGS
SetOutPath "$INSTDIR"
SetOverwrite ifnewer
Call SetMarquee
SectionEnd


;Page custom validateSerial
Function SerialPageShow
ReserveFile "validateSerial.ini"
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
!insertmacro MUI_INSTALLOPTIONS_EXTRACT "validateSerial.ini"
!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

Function SerialPageLeave

## Pop values from stack
Pop $R1
Pop $R2
Pop $R3
Pop $R4
Pop $R5

;!insertmacro MUI_HEADER_TEXT "Validating..." "Please Wait"
;!insertmacro MUI_INSTALLOPTIONS_DISPLAY "validateSerial.ini"

;MessageBox MB_OK "Break1"

StrCmp $R1 '1234' +3
MessageBox MB_OK|MB_ICONEXCLAMATION "Please enter vaild serial number!"
Abort

StrCmp $R2 '5678' +3
MessageBox MB_OK|MB_ICONEXCLAMATION "Please enter vaild serial number!"
Abort

StrCmp $R3 '9098' +3
MessageBox MB_OK|MB_ICONEXCLAMATION "Please enter vaild serial number!"
Abort

StrCmp $R4 '7654' +3
MessageBox MB_OK|MB_ICONEXCLAMATION "Please enter vaild serial number!"
Abort

StrCmp $R5 '3210' +3
MessageBox MB_OK|MB_ICONEXCLAMATION " Please enter vaild serial number!"
Abort
FunctionEnd

Function ConnectInternet
Push $R0

ClearErrors
Dialer::AttemptConnect
IfErrors noie3

Pop $R0
StrCmp $R0 "online" connected
MessageBox MB_OK|MB_ICONSTOP "Cannot connect to the internet."
Quit ;This will quit the installer.
;You might want to add your own error handling.

noie3:

; IE3 not installed
MessageBox MB_OK|MB_ICONINFORMATION \
"Please connect to the internet now."

connected:

Pop $R0

FunctionEnd

Function SetMarquee
FindWindow $0 "#32770" "" $HWNDPARENT
GetDlgItem $0 $0 1004
System::Call user32::GetWindowLong(ir0,i-16)i.r1
IntOp $1 $1 | 8 # PBS_MARQUEE
System::Call user32::SetWindowLong(ir0,i-16,ir1)
IntOp $1 ${WM_USER} + 10
SendMessage $0 $1 1 200 $2
FunctionEnd

Section -IPCheck
Internet::GetLocalHostIP ${VAR_1}
push $1
call ValidateIP
${If} ${Errors}
MessageBox MB_OK|MB_ICONINFORMATION "Your IP address: $1 and INVAILD"
Quit
${Else}
MessageBox MB_OK|MB_ICONINFORMATION "IP Address is vaild and will continue with installation process"
;!insertmacro MUI_INSTALLOPTIONS_EXTRACT "validateSerial.ini"

${EndIf}

SectionEnd

Section -Prerequisites

SetOutPath $INSTDIR
MessageBox MB_YESNO "Install the python open source package?" /SD IDYES IDNO endNetCF
File "python.msi"
ExecWait '"msiexec" /i "$INSTDIR\python.msi"'
endNetCF:

SectionEnd

Please help me out with verfication of the code.As you said i dont want to skip custom page(serialcheck) until verified.

Thanks alot.

Appreciate your help..


So you want to first validate the user's IP address and then ask them for the serial?

Stu


Stu,

Ya i want to validate users IP address and on the success need to move on for serial check .

Thanks,

Veeeru


Right. I see you've put your IP address check in a section... Sections are executed on the InstFiles page, which you have after your custom page.

You need to move it into the custom page function. Also, you've got ${If} ${Errors} in there, but no ClearErrors before you call the ValidateIP function.

Stu


Hello Stu,

Thanks alot, Could you please tell me how to write an .ini file for that IP check section for changing in to custom page.


Thanks.


You want the user to enter their IP address or something?

Stu


No.. user will not enter any IP address. I am trying to get their IP address using Internet plugin and comparing that with required range by calling the validationIP function written in .nsh file.

So can you give some idea regarding how to change in to IPcheck section in to custom page.


Thanks alot


You don't need a custom page then if you don't want any user input. Just put it in the show function of your serial page.

Stu


Stu,

Thanks alot and really appreciate your help..yaa its sorted out.


No problem. If you need any modifications or if you have any suggestions for the PassDialog plug-in let me know.

Stu