0

I am trying to create an exe file using NSIS script, in my script i am copying a batch file and a folder inside the already installed Jasper Server directory(It could be any directory)

This is my NSIS script--

   * Section 
     SetOutPath "C:\PROGRA~2\JASPER~1.0\buildomatic"

      File /r "C:\Users\Desktop\K-installer\backup3101"
       File "C:\Users\Desktop\K-installer\batch\demo.bat"
         ExecWait '"C:\PROGRA~2\JASPER~1.0\buildomatic\demo.bat"'
    SectionEnd  *

that is working fine when jasper server is installed in Program Files(x86). How can i generalize it for both Program Files and Program Files(x86).

Sharad
  • 3,562
  • 6
  • 37
  • 59
  • 3
    possible duplicate of [How to create a batch file which work for both Program Files and Program Files(x86)?](http://stackoverflow.com/questions/10071300/how-to-create-a-batch-file-which-work-for-both-program-files-and-program-filesx) – Helen Apr 09 '12 at 11:14

1 Answers1

1

This might not be super elegant but you can check if the directory "C:\PROGRA~2\JASPER~1.0\buildomatic" exists for "Program Files(x86)" and check if "C:\PROGRA~1\JASPER~1.0\buildomatic" for "Program Files". Then you can can do individual branching and handle everything according to your needs there.

Here you find how:

http://nsis.sourceforge.net/IfFileExists_Changes_Section_Flags

I hope this has helped you.

Edit: You might want to try something like this (warning not tested):

Section /o "Program Files(x86)"   prg2
    SetOutPath "C:\PROGRA~2\JASPER~1.0\buildomatic"
    File /r "C:\Users\Desktop\K-installer\backup3101"
    File "C:\Users\Desktop\K-installer\batch\demo.bat"
    ExecWait '"C:\PROGRA~2\JASPER~1.0\buildomatic\demo.bat"'
SectionEnd

Section /o "Program Files)"   prg1
    SetOutPath "C:\PROGRA~1\JASPER~1.0\buildomatic"
    File /r "C:\Users\Desktop\K-installer\backup3101"
    File "C:\Users\Desktop\K-installer\batch\demo.bat"
    ExecWait '"C:\PROGRA~1\JASPER~1.0\buildomatic\demo.bat"'
SectionEnd

Function .onInit
IfFileExists C:\PROGRA~1\JASPER~1.0\buildomatic Prog1Exists PastProg1Exists
Prog1Exists:
  ; Use the macro from sections.nsh
  !insertmacro SelectSection ${prg1}
PastProg1Exists:

IfFileExists C:\PROGRA~2\JASPER~1.0\buildomatic Prog2Exists PastProg2Exists
Prog2Exists:
  ; Use the macro declared above
  !insertmacro SelectSection ${prg2}
PastProg2Exists:

FunctionEnd
HardCoder
  • 3,026
  • 6
  • 32
  • 52
  • Can we change Function .onInit name because its already exist? – Sharad Apr 09 '12 at 13:22
  • You can as an example rename the "Function .onInit" to "Function Hello" and then call it from somewhere else with "Call Hello". You can read more about that here: http://nsis.sourceforge.net/Macro_vs_Function – HardCoder Apr 09 '12 at 15:41
  • Don't check xxx~#, it might not be program files, it could be anything! – Anders Apr 09 '12 at 18:05