- NSIS Discussion
- Executing an executable file
Archive: Executing an executable file
Niharika1588
11th January 2013 16:15 UTC
Executing an executable file
I want to run the executable file, automatically when the installation is going on. So I used Exec and ExecWait but both are not working. Could some one help me in figuring out this??
It doesn't show any error, but doesn't the files to folder "c".
FYI : The executable file is working fine, I tested it and the executable file is placed in the same folder as this file, so it isn't giving any error information like "File open failed/no such file".
Section "deploy_0.zip"
SetOutPath "C:\Users\Niharika\Downloads\Desktop\Tryng\c"
;File sji.exe //If I am uncommenting this, it is jus copying this file to the folder "c" that's it.
ExecWait ' "C:\Users\Niharika\Downloads\Desktop\Tryng\sji.exe" '
WriteUninstaller "C:\Users\Niharika\Downloads\Desktop\Uninstall.exe"
SectionEnd
LoRd_MuldeR
11th January 2013 21:01 UTC
Sure, command File sji.exe does nothing but extract "sji.exe" (to the current $OUTDIR).
Also command ExecWait '"C:\Users\Niharika\Downloads\Desktop\Tryng\sji.exe"' is highly prone to fail! Hardcoded path "C:\Users\Niharika\Downloads\Desktop" will not exist on user's computer with probability of 99.9% ;)
Try this:
InitPluginsDir
File "oname=$PLUGINSDIR\sji.exe" "sji.exe"
ExecWait '"$PLUGINSDIR\sji.exe"'
This will extract "sij.exe" to a unique sub-folder (will be auto-generated) inside %TEMP% and run it from there. Will also be cleaned-up when the installer exits.
Niharika1588
12th January 2013 00:23 UTC
I tried the below code :
Section "deploy.zip"
InitPluginsDir
SetOutPath "C:\Users\Niharika\Downloads\Desktop\"
File "oname =${PLUGINSDIR}\sji.exe" "sji.exe"
ExecWait '"${PLUGINSDIR}\sji.exe"'
SectionEnd
But I get the following error :
File: "oname =${PLUGINSDIR}\sji.exe" -> no files found.
Usage: File [/nonfatal] [/a] ([/r] [/x filespec [...]] filespec [...] |
/oname=outfile one_file_only)
Error in script "C:\Users\Niharika\Downloads\Desktop\Tryng\wrk\AnalyzingBasic (2).nsi" on line 27 -- aborting creation process
But I have sji.exe in the same folder where I have this script, so is it that the code is nt being copied to temp folder??
And one more question is what exactly does PLUGINSDIR mean? And the TEMP folder you mentioned does it exist or a virtual one??
Sorry for asking so many questions, but I am newbie for NSIS Script :(
PoRtAbLe_StEaLtH
13th January 2013 06:23 UTC
Originally posted by Niharika1588
I tried the below code :
Section "deploy.zip"
InitPluginsDir
SetOutPath "C:\Users\Niharika\Downloads\Desktop\"
File "oname =${PLUGINSDIR}\sji.exe" "sji.exe"
ExecWait '"${PLUGINSDIR}\sji.exe"'
SectionEnd
But I get the following error :
File: "oname =${PLUGINSDIR}\sji.exe" -> no files found.
Usage: File [/nonfatal] [/a] ([/r] [/x filespec [...]] filespec [...] |
/oname=outfile one_file_only)
Error in script "C:\Users\Niharika\Downloads\Desktop\Tryng\wrk\AnalyzingBasic (2).nsi" on line 27 -- aborting creation process
But I have sji.exe in the same folder where I have this script, so is it that the code is nt being copied to temp folder??
And one more question is what exactly does PLUGINSDIR mean? And the TEMP folder you mentioned does it exist or a virtual one??
Sorry for asking so many questions, but I am newbie for NSIS Script :(
File
:"oname=${PLUGINSDIR}\sji.exe"
should be:
InitPluginsDir
File /oname=$PLUGINSDIR\sji.exe "sji.exe"
ExecWait $PLUGINSDIR\sji.exe
put sji.exe in same folder as script
when you call it.. NSIS will copy sji.exe to TEMP dir (Trash directory)
and execute.. then clean up as Mulder said.
$PLUGINSDIR is an internal variable.. so you don't have to define it.
if you wanted to copy sji.exe to desktop..
InitPluginsDir
File /oname=$PLUGINSDIR\sji.exe "sji.exe"
CopyFiles /Silent `$PLUGINSDIR\sji.exe` `$DESKTOP`
LoRd_MuldeR
13th January 2013 13:15 UTC
Originally posted by PoRtAbLe_StEaLtH
[PHP]should be:
InitPluginsDir
File /oname=$PLUGINSDIR\sji.exe "sji.exe"
ExecWait $PLUGINSDIR\sji.exe
Oups, forgot the
/oname in my example :stare:
Originally posted by PoRtAbLe_StEaLtH
if you wanted to copy sji.exe to desktop..
InitPluginsDir
File /oname=$PLUGINSDIR\sji.exe "sji.exe"
CopyFiles /Silent `$PLUGINSDIR\sji.exe` `$DESKTOP`
In that case, however, it would be more convenient to extract it to Desktop right away:
File "/oname=$DESKTOP\sji.exe" "sji.exe"
Or:
SetOutPath "$DESKTOP"
File "sji.exe"
Niharika1588
13th January 2013 19:32 UTC
Thank you for the replies both of you.
I tried with /oname also earlier, but didn't work.
Now why do I need to use the copyFiles option, I don't want to just copy the executable files.
The need the executable file to be executed automatically, because it's like nested executable files.
The below command is working :
ZipDLL::extractall "C:\Users\Niharika\Downloads\Desktop\Tryng\wrk\client_9_6_0_0.zip" "C:\Users\Niharika\Downloads\Desktop\Tryng\c"
Here we are passing the zip file and using this command it is extracting the zip files to "C:\Users\Niharika\Downloads\Desktop\Tryng\c" folder which is what I want exactly.
Previously, what I had done is sji.exe will have all the files in the zip, once extracted it should copy to the folder.
Thanks a lot guys for the help.
LoRd_MuldeR
14th January 2013 01:26 UTC
Originally posted by Niharika1588
Thank you for the replies both of you.
I tried with /oname also earlier, but didn't work.
What
exactly did not work?
Originally posted by Niharika1588
Now why do I need to use the copyFiles option, I don't want to just copy the executable files
You do
NOT need CopyFiles, if you just want to extract (and run) files!
Originally posted by Niharika1588
The need the executable file to be executed automatically, because it's like nested executable files.
Then do it as suggested before!
InitPluginsDir
File "/oname=$PLUGINSDIR\NestedInstaller.exe" "NestedInstaller.exe"
ExecWait '"$PLUGINSDIR\NestedInstaller.exe"'
Be aware: If the NestedInstaller.exe installer actually extracts+runs yet another EXE file, the
ExecWait would wait for the NestedInstaller.exe but
not for the child process that NestedInstaller.exe has created.
Originally posted by Niharika1588
The below command is working :
ZipDLL::extractall "C:\Users\Niharika\Downloads\Desktop\Tryng\wrk\client_9_6_0_0.zip" "C:\Users\Niharika\Downloads\Desktop\Tryng\c"
Here we are passing the zip file and using this command it is extracting the zip files to "C:\Users\Niharika\Downloads\Desktop\Tryng\c" folder which is what I want exactly.
Previously, what I had done is sji.exe will have all the files in the zip, once extracted it should copy to the folder.
Thanks a lot guys for the help.
So do I get this right? You now package a ZIP file in your NSIS installer? If so, you would have to (1) make your installer extract the ZIP file and (2) extract the actual files from the previously extracted ZIP file using ZipDLL.
BUT: Is there really a good reason why you package a ZIP file (it means you actually have
two layers of compression!) instead of just packing the "client" files in your NSIS installer ???
You can do:
;Set path where to extract the "client" files
SetOutPath "$DESKTOP\Client"
;Now extract those files
File /r "client\*.*"
This code assumes that the "client" files are located in the sub-folder "client" within the folder where your .nsi file located
when the installer is built. With that code there will be no ZIP file needed.
Also: Get rid of those hardcoded paths like "C:\Users\Niharika\Downloads\Desktop\Tryng\wrk" from your installer! On the users computer "C:\Users\Niharika" won't exist and your installer will fail horribly !!!
Niharika1588
14th January 2013 16:17 UTC
The reason why I package a ZIP file in the installer is due to the flow of work in our organization. To be precise that's what exactly my boss wants me to do.
I couldn't modify it, since it's how the flow works.
Thanks for the information. It helped me a lot, but I have one more question.
For eg, if I want to copy a file I use :
File Client_9.zip.
What if the user wants to enter the Client_9.zip as an input, from some textbox that we provide to the user??
Is there a way to provide how we can implement this??
LoRd_MuldeR
14th January 2013 18:12 UTC
Originally posted by Niharika1588
The reason why I package a ZIP file in the installer is due to the flow of work in our organization. To be precise that's what exactly my boss wants me to do.
I couldn't modify it, since it's how the flow works.
You can extract the ZIP file
right at the moment when your installer is being built and then only include the files extracted from the ZIP file.
This could even be automated using the
!system built-time command...
Originally posted by Niharika1588
Thanks for the information. It helped me a lot, but I have one more question.
For eg, if I want to copy a file I use :
File Client_9.zip.
This does
not "copy" anything! It
extracts the file "Client_9.zip", from the installer, into the current $OUTDIR. And it's also what causes the file "Client_9.zip" to be included in your installer.
Originally posted by Niharika1588
What if the user wants to enter the Client_9.zip as an input, from some textbox that we provide to the user??
Is there a way to provide how we can implement this??
What exactly is the user supposed to provide from a text box ??? :confused:
(1)
Target path of the directory to where "Client_9.zip" shall be extracted?
(2) File name to which "Client_9.zip" shall be extracted, in current $OUTDIR?
(3)
Source path from where the file "Client_9.zip" shall be copied to somewhere else?
(4) Something else?
Niharika1588
14th January 2013 19:36 UTC
Sorry for the inappropriate questions.
I thought about it later and came to know that it isn't possible. I missed the most silly think that to extract the file it must be present in the executable file and adding all the files increases its size.
Anyhave, glad to meet you. Thanks for the help!!
Have a great day!!