- NSIS Discussion
- .nsi Script Question
Archive: .nsi Script Question
aeroelim
14th April 2008 22:29 UTC
.nsi Script Question
I was creating a .nsi script to test and practice making a .nsi script.
This is my code so far:
Name "Test1"
;
Page directory
Page instfiles
;
;
InstallDir $PROGRAMFILES\NSIS_Test
;
Section "!TestProgram"
SetOutPath $INSTDIR
File test1.txt
File test2.txt
File test3.txt
;
SectionEnd
;
;
Section /o "Uninstall"
WriteUninstaller $INSTDIR\Uninstal.exe
Delete $INSTDIR\test1.txt
Delete $INSTDIR\test2.txt
RMDir $INSTDIR
SectionEnd
Now heres my question:
Before I compile how do I set the test1.txt, test2.txt, test3.txt to be included? Because when I compile it says those files are missing, so how do I include them into the script beyond putting in the "File xxx" tag? Can somebody please help me, thanks!
AaronLS
14th April 2008 22:34 UTC
As you have it written, when you compile, NSIS compiler will look for those three txt files in the same directory as your nsi script. Do you have three files of those names in the same directory as the *.nsi file?
aeroelim
14th April 2008 23:46 UTC
Oh! You have to put it in the same folder as your *.nsi file! Thanks AaronLS, also I have a question for you, do you know any links to good tutorials on writting *.nsi script files?
AaronLS
15th April 2008 00:02 UTC
;) You can get really fancy and specify a relative path such as:
File "SubDirectory/file.txt"
File "../SameLevelDirectory/file.txt"
I began my NSIS adventure by running NSIS fromt he Start menu and choosing "NSIS Users Manual" under documentation and reading through a good portion of the manual. For example, there is lots more information about the "File" command.
Tutorials:
http://nsis.sourceforge.net/Category:Tutorials
That website has lots of other sections with good information.
aeroelim
15th April 2008 00:23 UTC
Thanks, but I have one more question.
I can't seem to get the uninstaller to work..
Here is my code now
Name "Test1"
;
OutFile installer.exe
;
Page components
Page directory
Page instfiles
;
;
InstallDir $PROGRAMFILES\NSIS_Test
;
Section /o "TestProgram"
SetOutPath $INSTDIR
File test1.txt
File test2.txt
File test3.txt
;
SectionEnd
;
Section /o "Uninstaller"
WriteUninstaller $INSTDIR\uninstall.exe
SectionEnd
Section "!Optional Program Files"
SetOutPath $INSTDIR\Test
File test4.txt
File test5.txt
SectionEnd
;
Section "!Optional Program Filesv2"
SetOutPath $INSTDIR\Test\Test2
File test6.txt
SectionEnd
;
;
Section /o "Uninstall"
Delete $INSTDIR\uninstall.exe
Delete $INSTDIR\test1.txt
Delete $INSTDIR\test2.txt
Delete $INSTDIR\test3.txt
Delete $INSTDIR\Test\test4.txt
Delete $INSTDIR\Test\test5.txt
Delete $INSTDIR\Test\Test2\test6.txt
SectionEnd
But when I run the uninstaller in the end it doesn't do anything, it just says "Completed" but no files were removes. How do I fix this?
AaronLS
15th April 2008 00:44 UTC
Remove the /o from the Uninstaller section and see if that helps.
aeroelim
15th April 2008 00:46 UTC
AaronLS, how do you put the installer in ModernUI?
I've tried
MUI_PAGE_WELCOME and other MUI_PAGE's but it says unknown command. Then I tried
!insertmacro MUI_PAGE_WELCOME but then it says it can't find the macro. How do i fix this?
AaronLS
15th April 2008 00:51 UTC
You have to include MUI.nsh or
!include "MUI2.nsh"
I think there is a few MUI example scripts in the NSIS install directory under examples:
C:\program files\NSIS\Examples\Modern UI\
Koopa
15th April 2008 00:55 UTC
E.g.
!include "MUI.nsh"
; MUI Settings
!define MUI_ABORTWARNING
!define MUI_HEADERIMAGE
!define MUI_HEADERIMAGE_BITMAP "${NSISDIR}\Contrib\Graphics\Header\orange.bmp"
!define MUI_WELCOMEFINISHPAGE_BITMAP "${NSISDIR}\Contrib\Graphics\Wizard\orange.bmp"
!define MUI_COMPONENTSPAGE_CHECKBITMAP "${NSISDIR}\Contrib\Graphics\Checks\simple-round.bmp"
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\orange-install.ico"
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\orange-uninstall.ico"
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!define MUI_UNINSTALLER
aeroelim
15th April 2008 01:06 UTC
how do you add text to a page in MUI_? I tried doing:
MUI_WELCOMEPAGE_TEXT "text"
under the !insertmacro MUI_PAGE_WELCOME but it doesn't work to add any text or anything, how do I do this?
AaronLS
15th April 2008 01:10 UTC
You need !define and I think it needs to come before the page declaration if I remember correctly.
!define MUI_WELCOMEPAGE_TEXT "text"
!insertmacro MUI_PAGE_WELCOME
aeroelim
15th April 2008 22:34 UTC
Now im running into this problem... Im trying to put a function to do a .onMouseOverSection function command but everything I try it just gives me an error in the compile..
(Note I want to put a mouseover message on the "Test Program" SECTION. Thanks!)
This is my whole code so far :
Name "TestInst"
OutFile installer1_1.exe
Function .onMouseOverSection
FindWindow $RO "Test Program" $HWNDPARENT $TESTPROGRAM
SendMessage $RO ${WM_SETTEXT} 0 "STR: REQUIRED TEST PROGRAM SECTION PLEASE DO"
FunctionEnd
Function .onInit
MessageBox MB_YESNO "This will install My Program. Do you wish to continue?" IDYES gogogo
Abort
gogogo:
FunctionEnd
Function un.onInit
MessageBox MB_YESNO "This will completely remove 'MY PROGRAM' from your computer. Do you wish to continue?" IDYES gogogo
Abort
gogogo:
FunctionEnd
!include MUI2.nsh
!define MUI_WELCOMEPAGE_TITLE "Welcome to test install!"
!define MUI_WELCOMEPAGE_TEXT "Welcome to test install! This is an installer testing my script creating skills!"
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!define MUI_FINISHPAGE_TITLE "Congratulations!"
!define MUI_FINISHPAGE_TEXT "Your install has completed succesfully if you have made it to this page! GRATZ!"
!define MUI_FINISHPAGE_BUTTON "Finish and Close"
!insertmacro MUI_PAGE_FINISH
!define MUI_WELCOMEPAGE_TEXT "Welcome to the uninstaller for the Test Program!"
!insertmacro MUI_UNPAGE_WELCOME
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!define MUI_FINISHPAGE_TEXT "The Test Program has completed un-installation! The program is now completely removed from your computer. If you wish you can check to see if the Directory is still there but it shouldn't be!"
!insertmacro MUI_UNPAGE_FINISH
InstallDir $PROGRAMFILES\_TEST
Section "!Test Program"
MessageBox MB_OK "The Installation has started! Please Wait while the installation continues"
SetOutPath $INSTDIR
File 1.txt
File 2.txt
File readme.txt
File help.txt
SetOutPath $INSTDIR\materials
File wep1.txt
File wep2.txt
SetOutPath $INSTDIR\maps
File 2tower.txt
File aces.txt
File city.txt
SectionEnd
Section /o "Custom Maps"
SetOutPath $INSTDIR\maps
File red.txt
File blue.txt
File yellow.txt
File green.txt
SectionEnd
Section /o "Uninstaller"
WriteUninstaller $INSTDIR\Uninstall.exe
SectionEnd
Section "Uninstall"
Delete $INSTDIR\Uninstall.exe
Delete $INSTDIR\maps\red.txt
Delete $INSTDIR\maps\blue.txt
Delete $INSTDIR\maps\yellow.txt
Delete $INSTDIR\maps\green.txt
Delete $INSTDIR\maps\2tower.txt
Delete $INSTDIR\maps\aces.txt
Delete $INSTDIR\maps\city.txt
RMDir $INSTDIR\maps
Delete $INSTDIR\materials\wep1.txt
Delete $INSTDIR\materials\wep2.txt
RMDir $INSTDIR\materials
Delete $INSTDIR\readme.txt
Delete $INSTDIR\help.txt
Delete $INSTDIR\1.txt
Delete $INSTDIR\2.txt
RMDir $INSTDIR
SectionEnd
AaronLS
15th April 2008 22:52 UTC
The compile errors indicates line 7 is the problem, and also gives this output:
Usage: FindWindow $(user_var: handle output) WindowClass [WindowTitle] [Window_Parent] [Child_After]
This means there is a probalem with your FindWindow statement.
According to the FindWindow documentation in the manual, the first parameter must be a user var. You are using $R0, but you should be using a variable you declared such as :
Var /GLOBAL $FoundWindow