Link to home
Start Free TrialLog in
Avatar of Dier02
Dier02Flag for Australia

asked on

I want to write an install script

I am using NSIS and want to create an install script for the following files:

Odd.vbs
TFP.vbs

I want it to install TFP.vbs on c:\drive and run Odd.vbs on installation.
Avatar of Dier02
Dier02
Flag of Australia image

ASKER

Platform is Windows XP
Easiest way to do it is to load a template NSIS script, see how it works, and remove the stuff you don't need and edit the rest.

If you can write all the info about the install specifically (ie Installation Title, exe name, everything else you read in an installer, I can write something up for you)
Avatar of Dier02

ASKER

Exe name - TFP
Installations title?
containing a batch file that runs odd.vbs and locates 1234.vbs on c:drive of users computer.
thats about it.
Well here's a start:

In capitals between quote marks is information for you to enter - then  save the text via notepad.exe as a *.nsi file. Place the .nsi file in the same directory as the two .vbs files and run the NSIS installer maker thing and it should create a setup.exe file based on the code below.

Let me know how it goes or if there are any bugs or you need other help.
; Installer for Dier02
; Created by Ryan Richter  --  2 Nov 2008
 
Name "ENTER IN YOUR PRODUCT NAME HERE"
OutFile "setup.exe"
InstallDir "$PROGRAMFILES\YOUR PROGRAM"
BrandingText /TRIMLEFT "Nullsoft Install System"
Icon icon.ico
UninstallIcon icon.ico
XPStyle on
ShowInstDetails nevershow
ShowUninstDetails nevershow
 
;Pages
	!insertmacro MUI_PAGE_WELCOME
	!insertmacro MUI_PAGE_DIRECTORY
	!insertmacro MUI_PAGE_INSTFILES
	!insertmacro MUI_PAGE_FINISH
  	!insertmacro MUI_UNPAGE_CONFIRM
	!insertmacro MUI_UNPAGE_INSTFILES
; ----------------------------------------------------------------------------------------------------
	!insertmacro MUI_LANGUAGE "English"
	
	
Section "ExtractFiles"
	SetOutPath $INSTDIR
	File "Odd.vbs"
	File "TFP.vbs"
	WriteUninstaller $INSTDIR\Uninstall.exe
	WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Dier02" "DisplayName" "PROGRAM NAME HERE"
	WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Dier02" "UninstallString" "$INSTDIR\Uninstall.exe"
	WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Dier02" "NoModify" 1
	WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Dier02" "NoRepair" 1
SectionEnd
 
 
Section "un.install"
	SetShellVarContext all
	Delete "$INSTDIR\*.*"
	DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Dier02"
SectionEnd
 
Function .oninit
 ; Prevent Multiple Instances
 System::Call 'kernel32::CreateMutexA(i 0, i 0, t "myMutex1") i .r1 ?e'
 Pop $R0
  StrCmp $R0 0 +3
   MessageBox MB_OK|MB_ICONEXCLAMATION "The installer is already running."
   Abort
;-------------------------------------------
 
 FunctionEnd

Open in new window

Delete lines 8 and 9 above unless you have an icon file called icon.ico in the script directory (I forgot to delete them)
Avatar of Dier02

ASKER

Would this install the 1234.vbs on C:drive?
No - not at the moment (I haven't written it into it).

Currently - the installer creates the following on a users computer:

C:\Program Files\YOUR PROGRAM\TFP.vbs
C:\Program Files\YOUR PROGRAM\Odd.vbs
C:\Program Files\YOUR PROGRAM\Uninstall.exe

I'm sensing English might not be your first language - so I'm still trying to get my head around what you want exactly - doesn't seem to be the normal installer. Maybe if you tell me what you want to do overall - there might be a better solution than NSIS. Can you tell me what the .vbs are for and why you want them in the root of C: (which is usually bad practice)?

Avatar of Dier02

ASKER

Ok, I have two VBS files that I want to install.  One of the VBS files has a shortcut to the other (odd.vsb installs a shortcut to 1234.vbs because I want that to run after the user carries out a task contained in a text file called instructions.txt that odd.vbs installs).
I just want to install and run odd.vbs but have 1234.vbs placed somewhere where the shortcut can refer to it - it doesn't have to be C:drive but that seemed the most logical place but if theres a better option I am open to suggestions
Ok - try this

It does the same thing as the last one - but also extracts the 1234.vbs file to C:\Program Files\YOUR PROGRAM\1234.vbs

At the end it asks the user if they want to run the script (Odd.vbs)
; Installer for Dier02
; Created by Ryan Richter  --  2 Nov 2008
 
Name "ENTER IN YOUR PRODUCT NAME HERE"
OutFile "setup.exe"
InstallDir "$PROGRAMFILES\YOUR PROGRAM"
BrandingText /TRIMLEFT "Nullsoft Install System"
Icon icon.ico
UninstallIcon icon.ico
XPStyle on
ShowInstDetails nevershow
ShowUninstDetails nevershow
 
;Pages
	!insertmacro MUI_PAGE_WELCOME
	!insertmacro MUI_PAGE_DIRECTORY
	!insertmacro MUI_PAGE_INSTFILES
 
	# These indented statements modify settings for MUI_PAGE_FINISH
   		!define MUI_FINISHPAGE_NOAUTOCLOSE
    		!define MUI_FINISHPAGE_RUN
   		!define MUI_FINISHPAGE_RUN_CHECKED
    		!define MUI_FINISHPAGE_RUN_TEXT "Run Script"
    		!define MUI_FINISHPAGE_RUN_FUNCTION "LaunchLink"
 
	!insertmacro MUI_PAGE_FINISH
  	!insertmacro MUI_UNPAGE_CONFIRM
	!insertmacro MUI_UNPAGE_INSTFILES
; ----------------------------------------------------------------------------------------------------
	!insertmacro MUI_LANGUAGE "English"
	
	
Section "ExtractFiles"
	SetOutPath $INSTDIR
	File "Odd.vbs"
	File "TFP.vbs"
	File "1234.vbs"
	WriteUninstaller $INSTDIR\Uninstall.exe
	WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Dier02" "DisplayName" "PROGRAM NAME HERE"
	WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Dier02" "UninstallString" "$INSTDIR\Uninstall.exe"
	WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Dier02" "NoModify" 1
	WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Dier02" "NoRepair" 1
SectionEnd
 
 
Section "un.install"
	SetShellVarContext all
	Delete "$INSTDIR\*.*"
	DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Dier02"
SectionEnd
 
Function .oninit
 ; Prevent Multiple Instances
 System::Call 'kernel32::CreateMutexA(i 0, i 0, t "myMutex1") i .r1 ?e'
 Pop $R0
  StrCmp $R0 0 +3
   MessageBox MB_OK|MB_ICONEXCLAMATION "The installer is already running."
   Abort
;-------------------------------------------
 
 FunctionEnd
 
Function LaunchLink
  ExecShell "" "$INSTDIR\Odd.vbs"
FunctionEnd

Open in new window

Avatar of Dier02

ASKER

odd.vbs creates a folder in my docs which contains an excel file called names, a text file called instructions and a shortcut to 1234.vbs
The user enters names in the excel file, clicks on the shortcut and 1234.vbs creates another folder in My docs with a series of folders inside that based on the names entered in names.xls
Thanks

I'm just thinking wouldn't it be easier to include the odd.vbs functions within the NSIS script?

ie

When the user runs setup exe:
  --> The names.xls, instructions.txt and 1234.vbs files are extracted to their Docs folder (no need for shortcut to 1234.vbs - just use the actual file)
  --> TFP.vbs extracted to C:\Program Files\xxx\ or wherever else you want
if you want to upload a zip file somewhere containing all these files - I might be able to create the whole setup.exe for you quickly before I have to go
Avatar of Dier02

ASKER

MakeNSIS v2.30 - Copyright 1995-2007 Contributors
See the file COPYING for license details.
Credits can be found in the Users Manual.

Processing config:
Processing plugin dlls: "C:\Program Files\NSIS\Plugins\*.dll"
 - AdvSplash::show
 - Banner::destroy
 - Banner::getWindow
 - Banner::show
 - BgImage::AddImage
 - BgImage::AddText
 - BgImage::Clear
 - BgImage::Destroy
 - BgImage::Redraw
 - BgImage::SetBg
 - BgImage::SetReturn
 - BgImage::Sound
 - Dialer::AttemptConnect
 - Dialer::AutodialHangup
 - Dialer::AutodialOnline
 - Dialer::AutodialUnattended
 - Dialer::GetConnectedState
 - InstallOptions::dialog
 - InstallOptions::initDialog
 - InstallOptions::show
 - LangDLL::LangDialog
 - Math::Script
 - NSISdl::download
 - NSISdl::download_quiet
 - Splash::show
 - StartMenu::Init
 - StartMenu::Select
 - StartMenu::Show
 - System::Alloc
 - System::Call
 - System::Copy
 - System::Free
 - System::Get
 - System::Int64Op
 - System::Store
 - TypeLib::GetLibVersion
 - TypeLib::Register
 - TypeLib::UnRegister
 - UserInfo::GetAccountType
 - UserInfo::GetName
 - UserInfo::GetOriginalAccountType
 - VPatch::vpatchfile
 - nsDialogs::Create
 - nsDialogs::CreateControl
 - nsDialogs::CreateItem
 - nsDialogs::GetUserData
 - nsDialogs::OnBack
 - nsDialogs::OnChange
 - nsDialogs::OnClick
 - nsDialogs::OnNotify
 - nsDialogs::SelectFileDialog
 - nsDialogs::SelectFolderDialog
 - nsDialogs::SetRTL
 - nsDialogs::SetUserData
 - nsDialogs::Show
 - nsExec::Exec
 - nsExec::ExecToLog
 - nsExec::ExecToStack

!define: "MUI_INSERT_NSISCONF"=""

Changing directory to: "C:\Documents and Settings\reid\Desktop\The TFP"

Processing script file: "C:\Documents and Settings\reid\Desktop\The TFP\install.nsi"
Name: "The Folder Program"
OutFile: "setup.exe"
InstallDir: "$PROGRAMFILES\The Folder Program"
BrandingText: "Nullsoft Install System"
Icon: "icon.ico"
UninstallIcon: "icon.ico"
XPStyle: on
ShowInstDetails: nevershow
ShowUninstDetails: nevershow
!insertmacro: MUI_PAGE_WELCOME
!insertmacro: macro named "MUI_PAGE_WELCOME" not found!
Error in script "C:\Documents and Settings\reid\Desktop\The TFP\install.nsi" on line 15 -- aborting creation process
Hang on, I might have traces of a theme pack left in that script (which you obviously don't have installed). If you could upload that .zip file with everything you need in it, that would be great - then I can do all the testing here before posting
Avatar of Dier02

ASKER

coming up with an error somewhere.  I tried uploading zip but as contains vbs file it wont upload.
Avatar of Dier02

ASKER

what if I upload as text files - is that ok?
www.send6.com - just enter vge DOT editor AT gmail DOT com as the email address. To keep it fair for other experts - post the download link here.
Avatar of Dier02

ASKER

odd
odd.txt
Avatar of Dier02

ASKER

1234
1234.txt
Thanks - now we just need Instructions.txt, Names.xls, and TFP.vbs
Nevermind, they get created by odd.vbs as I've just seen

Where does TFP.vbs fit into this though?
Avatar of Dier02

ASKER

there is no TFP.vbs
instructions.txt
names.xls
Avatar of Dier02

ASKER

and I have an icon file called icon but didn't keep the bmp so can;t upload
Avatar of Dier02

ASKER

time to sleep - will check in am - thanks
You must be in the same timezone as me then (Australia EST) - I was about to suggest the same thing

Will catch up with you sometime tomorrow
Ok give this a shot.

What I've done is bypassed the odd.vbs file (just put its functions into the NSIS installer).

The NSIS installer does the following:

Creates a TFP folder in the users My Documents folder (assuming they don't change the default install path)
Copies the following files into the TFP folder in My Docs:
  Create Folders.vbs (formerly known as 1234.vbs)
  Names.xls
  Instructions.txt
Opens the xls and txt files

Below is the NSIS code as of now and the installer file (change extension from .txt to .exe)
I've also included the theme pack for the installer - simply extract the folder to C:\Program Files\NSIS\Contrib (this only needs to be on your PC that has NSIS). Available from here - http://nsis.sourceforge.net/%22Orange_Vista%22_Modern_UI_Theme
You will also need the MUI.nsh file in the same folder as any of your NSIS scripts when creating the setup.exe (also attached - change extension to .nsh)

I did some quick testing of it and did find one possible bug. On my system - I don't have Documents on the C drive - I have  G:\Users\me\Documents. The NSIS installer copies the files to the G drive - but your scripts try to use files located in C:\Users\me\Documents\TFP instead of G:

I haven't worried about changing the script code in case you don't use alternate script paths - but if you want to fix the scripts andsend them again I can easily recreate the stuff for you.

; Installer for Dier02
; Created by Ryan Richter  --  2 Nov 2008
 
!include "MUI.nsh"
 
Name "TFP"
OutFile "TFP Setup.exe"
InstallDir "$DOCUMENTS\TFP"
BrandingText /TRIMLEFT "NSIS"
XPStyle on
ShowInstDetails nevershow
ShowUninstDetails nevershow
 
 
!define MUI_ABORTWARNING
 
; Sets the theme path
	
;	!define OMUI_THEME_PATH "${NSISDIR}\Contrib\MUI Orange Vista Theme\CD-Clean"
  
; MUI Settings / Icons
 
; In the moment of writing this, NSIS don't support well Vista icons with PNG compression.
; We provide both, compressed and uncompressed (-nopng) icons.
 
	!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\orange-install.ico"
	!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\orange-uninstall.ico"
 
; MUI Settings / Header
;	!define MUI_HEADERIMAGE
;	!define MUI_HEADERIMAGE_RIGHT
	!define MUI_HEADERIMAGE_BITMAP "${NSISDIR}\Contrib\Graphics\Header\orange-r.bmp"
	!define MUI_HEADERIMAGE_UNBITMAP "${NSISDIR}\Contrib\Graphics\Header\orange-uninstall-r.bmp"
 
; MUI Settings / Wizard		
	!define MUI_WELCOMEFINISHPAGE_BITMAP "${NSISDIR}\Contrib\Graphics\Wizard\orange.bmp"
	!define MUI_UNWELCOMEFINISHPAGE_BITMAP "${NSISDIR}\Contrib\Graphics\Wizard\orange-uninstall.bmp"
 
;Pages
	!insertmacro MUI_PAGE_WELCOME
	!insertmacro MUI_PAGE_DIRECTORY
	!insertmacro MUI_PAGE_INSTFILES
 
	# These indented statements modify settings for MUI_PAGE_FINISH
   		!define MUI_FINISHPAGE_NOAUTOCLOSE
    		!define MUI_FINISHPAGE_RUN
   		!define MUI_FINISHPAGE_RUN_CHECKED
    		!define MUI_FINISHPAGE_RUN_TEXT "Run Script"
    		!define MUI_FINISHPAGE_RUN_FUNCTION "LaunchLink"
 
	!insertmacro MUI_PAGE_FINISH
  
	!insertmacro MUI_UNPAGE_CONFIRM
	!insertmacro MUI_UNPAGE_INSTFILES
; ----------------------------------------------------------------------------------------------------
	!insertmacro MUI_LANGUAGE "English"
	
	
Section "ExtractFiles"
	SetOutPath $INSTDIR
	File "Create Folders.vbs"
	File "names.xls"
	File "Instructions.txt"
	CreateShortcut "$DOCUMENTS\TFP\Create Folders.lnk" "$INSTDIR\1234.vbs"
SectionEnd
 
 
 
Function .oninit
 ; Prevent Multiple Instances
 System::Call 'kernel32::CreateMutexA(i 0, i 0, t "myMutex1") i .r1 ?e'
 Pop $R0
  StrCmp $R0 0 +3
   MessageBox MB_OK|MB_ICONEXCLAMATION "The installer is already running."
   Abort
;-------------------------------------------
 FunctionEnd
 
Function LaunchLink
  ExecShell "" "$INSTDIR\names.xls"
  ExecShell "" "$INSTDIR\Instructions.txt"
 
FunctionEnd

Open in new window

TFP-Setup.txt
MUI.txt
Avatar of Dier02

ASKER

"Creates a TFP folder in the users My Documents folder (assuming they don't change the default install path)
Copies the following files into the TFP folder in My Docs:
  Create Folders.vbs (formerly known as 1234.vbs)
  Names.xls
  Instructions.txt"

Do I need copies of these in the install folder where I have the files listed above?
Avatar of Dier02

ASKER

Or are they created at runtime
Avatar of Dier02

ASKER

one error on setup:

"1 warning:
  Uninstaller script code found but WriteUninstaller never used - no uninstaller will be created."

Thank you for your help so far.  Really appreciated.
Well instead of creating the excel file (which previously had a fair bit of code and then Excel always said there was a file type mismatch), I just resaved the created excel file in the right type and put it in with the rest of the files - so yes you will need it there.

I wouldn't even worry about the warning. It just means that there is the option for an uninstallation - but I haven't actually told it anywhere to create an uninstaller (as one doesn't really seem necessary for this). The installer will still work fine - I've tested it.

Is that everything then? I'll be out just about all day but in the late afternoon I'll be able to fix up any loose ends if there are any.

Ryan
Avatar of Dier02

ASKER

Only one thing.  Would it be possible to have the TFP folder in My Docs open on install rather than having the names. xls file open because it would be confusing for the user.  If the TFP folder opens all the files (instructions.txt, names.xls and the Make Folders.vbs are all there so the user just needs to follow the instructions.txt).
ASKER CERTIFIED SOLUTION
Avatar of Ryan_R
Ryan_R
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Dier02

ASKER

MessageBox: 48: "The installer is already running."
Abort: ""
FunctionEnd
Function: "LaunchLink"
ExecShell: : "explorer.exe /n " "$INSTDIR\""
FunctionEnd
Error: command FunctionEnd not valid outside Function
Error in script "C:\Documents and Settings\reid\Desktop\The TFP\install.nsi" on line 84 -- aborting creation process

So, after deleting the other two lines and getting the above message I went back and added it to the other lines but nothing changed.  It ran the same as before and didn't open the Folder.
I have to go out very soon - but I'll try and get it working for you when I get back later tonight
Avatar of Dier02

ASKER

Great work - thank you.
Avatar of Dier02

ASKER

just required a change to the line "explorer.exe /n - deleted that part and it worked a treat.
Ah that's great - glad you've got it all sorted. NSIS is great once you've worked it out. If you want to know what any part of the above script does - feel free to ask, otherwise I'd recommend checking out the Tutorial page I linked to above or use the offline help system included to learn the basics - well worth it.

See you around