Simple tutorials: Difference between revisions
Line 119: | Line 119: | ||
You're a real deep tihkenr. Thanks for sharing. | You're a real deep tihkenr. Thanks for sharing. | ||
Heck yeah this is eaxtlcy what I needed. | |||
==Check if user is administrator== | ==Check if user is administrator== |
Revision as of 20:08, 15 May 2013
Author: eldri005 (talk, contrib) |
If this page is your first experience of NSIS, you will need the NSIS compiler to transform the following scripts, and any others you create, into functioning installers. makensisw.exe in the NSIS installation folder is the actual compiler. It has a graphical front end that explains three ways to load scripts, so it's very easy to use. Once you have installed NSIS, to create an installer, copy a script into a text editor, save the file with a .nsi extension, and load the file into the makensisw compiler.
The bare minimum
# name the installer OutFile "Installer.exe" # default section start; every NSIS script has at least one section. section # default section end sectionEnd
Simple hello world - popup box
This hello world script will create a popup box with the words "hello world" in it and an "OK" button, when the installer is run
# set the name of the installer outfile "hello world.exe" # create a default section. section # create a popup box, with an OK button and the text "Hello world!" messageBox MB_OK "Hello world!" sectionEnd
Zoho is a great way for teacher and sdenutts so that they can take their work where ever they go. Zoho is good for sdenutts because zoho allows them to take the that they have worked on home with them so that they can fix their work or have a parnet look at it so they can see how their student is doing in school. Zoho is good for teachers because it allows them to take their lesson plans that they worked on home with them so that they can make corrections on there lesson plans. There is just on problem with how Zoho works and that is that when your flies become to big or have to many files they will charge you.
Simply install a file
This installer script will copy the file "test.txt" to the installation directory. First, create the test.txt file in the same directory as the installer script below then compile the installer script. If the installer script is on the Desktop, delete the test.txt file before running the compiled installer. Running the simple installer installs the test.txt file to the Desktop.
# define the name of the installer outfile "simple installer.exe" # define the directory to install to, the desktop in this case as specified # by the predefined $DESKTOP variable installDir $DESKTOP # default section section # define the output path for this file setOutPath $INSTDIR # define what to install and place it in the output path File test.txt sectionEnd
Install a file and create an uninstaller to remove it
This script will do the following: create an installer named "installer.exe"; install a file named "test.txt" to the desktop; create an uninstaller named "uninstaller.exe" on the desktop. The uninstaller will remove itself and the installed text file.
# define installer name outFile "installer.exe" # set desktop as install directory InstallDir $DESKTOP # default section start section # define output path setOutPath $INSTDIR # specify file to go in output path File test.txt # define uninstaller name writeUninstaller $INSTDIR\uninstaller.exe #------- # default section end sectionEnd # create a section to define what the uninstaller does. # the section will always be named "Uninstall" section "Uninstall" # Always delete uninstaller first delete $INSTDIR\uninstaller.exe # now delete installed file delete $INSTDIR\test.txt sectionEnd
This installer creates a start menu item, nothing more
# Name the installer outFile "installer.exe" # default section section # create a shortcut named "new shortcut" in the start menu programs directory # presently, the new shortcut doesn't call anything (the second field is blank) createShortCut "$SMPROGRAMS\new shortcut.lnk" "" # to delete shortcut, go to start menu directory and manually delete it # default sec end sectionEnd
You're a real deep tihkenr. Thanks for sharing.
Heck yeah this is eaxtlcy what I needed.
Check if user is administrator
Sometimes, it's necessary to check if an installer's user has administrative privileges. This simple script checks for that using the "UserInfo" plugin. There's a more sophisticated alternative at http://forums.winamp.com/showthread.php?threadid=195020, but this method seems to work fine. Another example of UserInfo can be found in the NSIS installation directory under \Examples\UserInfo\UserInfo.nsi.
# name installer outFile "installer.exe" # default section start section # call userInfo plugin to get user info. The plugin puts the result in the stack userInfo::getAccountType # pop the result from the stack into $0 pop $0 # compare the result with the string "Admin" to see if the user is admin. # If match, jump 3 lines down. strCmp $0 "Admin" +3 # if there is not a match, print message and return messageBox MB_OK "not admin: $0" return # otherwise, confirm and return messageBox MB_OK "is admin" # default section end sectionEnd