Solved

I want to write an install script

Posted on 2008-11-01
39
1,561 Views
Last Modified: 2013-12-04
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.
0
Comment
Question by:Dier02
  • 20
  • 18
39 Comments
 

Author Comment

by:Dier02
ID: 22859063
Platform is Windows XP
0
 
LVL 15

Expert Comment

by:Ryan_R
ID: 22860971
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)
0
 

Author Comment

by:Dier02
ID: 22861018
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.
0
 
LVL 15

Expert Comment

by:Ryan_R
ID: 22861019
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

0
 
LVL 15

Expert Comment

by:Ryan_R
ID: 22861022
Delete lines 8 and 9 above unless you have an icon file called icon.ico in the script directory (I forgot to delete them)
0
 
LVL 15

Expert Comment

by:Ryan_R
ID: 22861032
0
 

Author Comment

by:Dier02
ID: 22861036
Would this install the 1234.vbs on C:drive?
0
 
LVL 15

Expert Comment

by:Ryan_R
ID: 22861046
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)?

0
 

Author Comment

by:Dier02
ID: 22861091
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
0
 
LVL 15

Expert Comment

by:Ryan_R
ID: 22861094
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

0
 

Author Comment

by:Dier02
ID: 22861101
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
0
 
LVL 15

Expert Comment

by:Ryan_R
ID: 22861113
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
0
 
LVL 15

Expert Comment

by:Ryan_R
ID: 22861118
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
0
 

Author Comment

by:Dier02
ID: 22861125
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
0
 
LVL 15

Expert Comment

by:Ryan_R
ID: 22861133
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
0
 

Author Comment

by:Dier02
ID: 22861134
coming up with an error somewhere.  I tried uploading zip but as contains vbs file it wont upload.
0
 

Author Comment

by:Dier02
ID: 22861138
what if I upload as text files - is that ok?
0
 
LVL 15

Expert Comment

by:Ryan_R
ID: 22861143
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.
0
 

Author Comment

by:Dier02
ID: 22861145
odd
odd.txt
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

Author Comment

by:Dier02
ID: 22861146
1234
1234.txt
0
 
LVL 15

Expert Comment

by:Ryan_R
ID: 22861157
Thanks - now we just need Instructions.txt, Names.xls, and TFP.vbs
0
 
LVL 15

Expert Comment

by:Ryan_R
ID: 22861162
Nevermind, they get created by odd.vbs as I've just seen

Where does TFP.vbs fit into this though?
0
 

Author Comment

by:Dier02
ID: 22861167
there is no TFP.vbs
instructions.txt
names.xls
0
 

Author Comment

by:Dier02
ID: 22861172
and I have an icon file called icon but didn't keep the bmp so can;t upload
0
 

Author Comment

by:Dier02
ID: 22861175
time to sleep - will check in am - thanks
0
 
LVL 15

Expert Comment

by:Ryan_R
ID: 22861178
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
0
 
LVL 15

Expert Comment

by:Ryan_R
ID: 22861268
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
0
 

Author Comment

by:Dier02
ID: 22863159
"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?
0
 

Author Comment

by:Dier02
ID: 22863160
Or are they created at runtime
0
 

Author Comment

by:Dier02
ID: 22863228
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.
0
 
LVL 15

Expert Comment

by:Ryan_R
ID: 22863510
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
0
 

Author Comment

by:Dier02
ID: 22864953
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).
0
 
LVL 15

Accepted Solution

by:
Ryan_R earned 500 total points
ID: 22864961
Sure - I'm taking a punt here - but I think all you need to do is change the function at the bottom of the script:

FROM:
 

Function LaunchLink

  ExecShell "" "$INSTDIR\names.xls"

  ExecShell "" "$INSTDIR\Instructions.txt"

FunctionEnd
 
 
 

TO:
 

Function LaunchLink

  ExecShell "" "explorer.exe /n "$INSTDIR\"

FunctionEnd
 
 

I haven't tested it - there might be issues with the quotes, etc - but dinner's just about ready and I'll be out later - you should be able to work it out from there.

Open in new window

0
 

Author Comment

by:Dier02
ID: 22865159
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.
0
 
LVL 15

Expert Comment

by:Ryan_R
ID: 22865173
I have to go out very soon - but I'll try and get it working for you when I get back later tonight
0
 

Author Closing Comment

by:Dier02
ID: 31512285
Great work - thank you.
0
 

Author Comment

by:Dier02
ID: 22865187
just required a change to the line "explorer.exe /n - deleted that part and it worked a treat.
0
 
LVL 15

Expert Comment

by:Ryan_R
ID: 22866053
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
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

The article will include the best Data Recovery Tools along with their Features, Capabilities, and their Download Links. Hope you’ll enjoy it and will choose the one as required by you.
Skype is a P2P (Peer to Peer) instant messaging and VOIP (Voice over IP) service – as well as a whole lot more.
Viewers will learn how to use the Hootsuite Dashboard.
The viewer will learn how to successfully download and install the SARDU utility on Windows 8, without downloading adware.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now