Archive: Sample script for a newbie


Sample script for a newbie
I know this is quite simple, but I have a problem with scripts and an example would help me a lot. I installed Venis.

I need a sample script that does the following:

Check if install, update or uninstall.

ModernUI with multi-languages

Install : check for admin rights, ask for a data directory, ask for a program directory, modify the ini file, place the ini file into the default windows directory,create folder, create shortcuts, copy 5 files (4 exe and one dll), regsvr the dll, place file1.exe into the registry to run at startup, start file1 and ask if file2.exe should be run.

Update: stop file1.exe, regsvr -u the dll, replace all files with the new version, regsvr the dll, restart file1.exe

Uninstall: stop the file1.exe, regsvr -u the dll, remove all registry keys, remove the program directory, ask if data directory should be deleted.


There are tons of examples in the NSIS distribution. There are also examples in the NSIS Archive.


Dear zimsms, I am aware that there are a lot of examples in the archive and the distribution, thank you for your incredible astuteness.

I am not a programmer and am running around trying to solve a number of problems at the same time. To learn a new script language just takes away time that I dont have.

Thus the help of some Senior Member, who in a couple of minutes could either point me to the right script or paste me a sample script, would help me a great deal.

Thanks for your help anyway


It's not that simple to just 'create' the code for you. If you want what you ask done (which will take some time) you should really do it yourself.
We can point you out to various things, but I really doubt anyone will want to write you a whole script (and the Install Options dialogue to go with it).

You say that you need two directories to be inputted by the user - This would require an InstallOptions dialogue to be created (see NSIS\Contrib\InstallOptions).

There are no scripts that do exactly as you ask (all installers are unique, none do exactly the same thing), but there will be code in examples that can be modified to do the individual tasks.

Rather than thinking of it as 'one big job' try breaking it down into steps. This is how a programmer works - he/she does not do the whole thing in one go (that would not be possible!)

If you really need to make this installer badly, then again you must do it with your own free will. I don't ask people to write my software or computer games. I have to make them myself along with the help of others if necessary!

NSIS has everything that you need. If you want to find a certain code element, you just need to search the NSIS documentation (NSIS.chm) and you should be going in no time. If you want to ask for help on parts, then we can help you.

-Stu


Thanks STu

I basically got everything going except for the part where I run the regsvr of a dll (and also regsvr -u) and the addidition of the registry key under windows "run" for the autostart. How do I add these to the script.

Thanks


For registrating/unregistrating files and writing a key to "run" ..you need to use this code:



Section
;registrating
RegDll "$VARIABLE\file.ext"
;unregistrating
UnRegDLL "$VARIABLE\file.ext"
;now writing the damn register key
WriteRegStr HKLM "Software\Microsoft\Windows\Run" "Appilication" "$VARIABLE\file.ect"

SectionEnd


NOTE: if you write that key to "run" then it will automaticly be checked in "msconfig.exe" under startup

you need to replace $VARIABLE to the path that the file is located here are those variables:

$PROGRAMFILES
The program files directory (usually C:\Program Files but detected at runtime).

$COMMONFILES
The common files directory. This is a directory for components that are shared across applications (usually C:\Program Files\Common Files but detected at runtime).

$DESKTOP
The windows desktop directory (usually C:\windows\desktop but detected at runtime). The context of this constant (All Users or Current user) depends on the SetShellVarContext setting. The default is the current user.

$EXEDIR
The location of the installer executable. (technically you can modify this variable, but it is probably not a good idea)

${NSISDIR}
A symbol that contains the path where NSIS is installed. Detected at compile time. Useful if you want to call resources that are in NSIS directory e.g. Icons, UIs...

$WINDIR
The windows directory (usually C:\windows or C:\winnt but detected at runtime)

$SYSDIR
The windows system directory (usually C:\windows\system or C:\winnt\system32 but detected at runtime)

$TEMP
The system temporary directory (usually C:\windows\temp but detected at runtime)

$STARTMENU
The start menu folder (useful in adding start menu items using CreateShortCut). The context of this constant (All Users or Current user) depends on the SetShellVarContext setting. The default is the current user.

$SMPROGRAMS
The start menu programs folder (use this whenever you want $STARTMENU\Programs). The context of this constant (All Users or Current user) depends on the SetShellVarContext setting. The default is the current user.

$SMSTARTUP
The start menu programs / startup folder. The context of this constant (All Users or Current user) depends on the SetShellVarContext setting. The default is the current user.

$QUICKLAUNCH
The quick launch folder for IE4 active desktop and above. If quick launch is not available, simply returns the same as $TEMP.

$DOCUMENTS
The documents directory. A typical path for the current user is C:\Documents and Settings\Foo\My Documents. The context of this constant (All Users or Current user) depends on the SetShellVarContext setting. The default is the current user.

$SENDTO
The directory that contains Send To menu shorcut items.

$RECENT
The directory that contains shortcuts to the user's recently used documents.

$FAVORITES
The directory that contains shortcuts to the user's favorite websites, documents, etc. The context of this constant (All Users or Current user) depends on the SetShellVarContext setting. The default is the current user.

$MUSIC
The user's music files directory. The context of this constant (All Users or Current user) depends on the SetShellVarContext setting. The default is the current user.

$PICTURES
The user's picture files directory. The context of this constant (All Users or Current user) depends on the SetShellVarContext setting. The default is the current user.

$VIDEOS
The user's video files directory. The context of this constant (All Users or Current user) depends on the SetShellVarContext setting. The default is the current user.

$NETHOOD
The directory that contains link objects that may exist in the My Network Places/Network Neighborhood folder.

$FONTS
The system's fonts directory.

$TEMPLATES
The document templates directory. The context of this constant (All Users or Current user) depends on the SetShellVarContext setting. The default is the current user.

$APPDATA
The application data directory. Detection of the current user path requires Internet Explorer 4 and above. Detection of the all users path requires Internet Explorer 5 and above. The context of this constant (All Users or Current user) depends on the SetShellVarContext setting. The default is the current user.

$PRINTHOOD
The directory that contains link objects that may exist in the Printers folder.

$INTERNET_CACHE
Internet Explorer's temporary internet files directory.

$COOKIES
Internet Explorer's cookies directory.

$HISTORY
Internet Explorer's history directory.

$PROFILE
The user's profile directory. A typical path is C:\Documents and Settings\Foo.

$ADMINTOOLS
A directory where administrative tools are kept. The context of this constant (All Users or Current user) depends on the SetShellVarContext setting. The default is the current user.

$RESOURCES
The resources directory that stores themes and other Windows resources (usually C:\Windows\Resources but detected at runtime)

$RESOURCES_LOCALIZED
The localized resources directory that stores themes and other Windows resources (usually C:\Windows\Resources\1033 but detected at runtime)

$CDBURN_AREA
A directory where files awaiting to be burned to CD are stored.

$HWNDPARENT
The decimal HWND of the parent window.

$PLUGINSDIR
The path to a temporary folder created upon the first usage of a plugin or a call to InitPluginsDir. This folder is automatically deleted when the installer exits. This makes this folder the ideal folder to hold INI files for InstallOptions, bitmaps for the splash plugin, or any other file that a plugin needs to work.


you can also see them in the manual under "variables"

you can also use this : "$PROGRAMFILES\Folder\Folder2
this is the folder (in my case) "C:\program files\Folder\Folder2"

Thanks VegetaSan

that already helps me a lot. Will post the complete script later.


no need to copy/paste when you can simply link to the manual