NSIS Simple SC plugin - quotes in "path to executable" - nsis

My installer using NSIS and the Simple SC plugin does not put quotes around the "Path to executable" of a Windows Service which I believe is a security issue.
How do I either make it have quotes around with the Simple SC plugin, or does anyone know of any other plugins for NSIS that I can use that would do that?

Have you tried just quoting the path?
SimpleSC::InstallService "MyService" "My Service Display Name" "16" "2" '"C:\MyPath\MyService.exe"' "" "" ""
Pop $0

Related

Fail to copying file in NSIS?

For copy file i use (code below) its work properly.
Section "one"
CreateDirectory $EXEDIR\dst
CopyFiles $EXEDIR\*.* $EXEDIR/dst
SectionEnd
When i use $PROGRAMFILES(only change the destination path) it create directory but copy doesn't work.
Section "two"
CreateDirectory $PROGRAMFILES\dst
CopyFiles $EXEDIR\*.* $PROGRAMFILES/dst
SectionEnd
where is the problem?
/ is not the path separator on Windows, use \. / is supported in a lot of places but not everywhere.
It might also be failing if you don't have write access to that folder so make sure you have RequestExectionLevel Admin in your script.
The only way to know for sure is to monitor the installer with Process Monitor...

Where can I add command line in the NSIS script

I would add some command line to customize my NSIS intaller. I already read some topics, I know I must use ${GetParameters} and ${GetOptions}. But the NSIS script is very long do I put him somewhere in the OnInit function or in a section at the beginning of the script ?
I want, for example, to add an --quiet command line which display all the pages except the license( something which seems to /S), I want to try something like that:
Var DisplayAllPages
Var DisplayLicense
${GetParameters} "quiet"
${GetOptions} "quiet" "--quiet"=DisplayLicense
But I don't Know where can I write
You can use ${GetParameters} and ${GetOptions} in any function and/or section.
Only .onInit and sections are executed when the installer is started with /S so if you wish to turn silent mode off you need to put the code in .onInit.
If you are storing the result in a global variable then .onInit is also a good place to call them so that the information is available to the rest of the installer.

check for file existence using nmake and delete it

I am using Windows version of NMAKE. I would like to check for file existence in a make file. If it exists I need to delete it. Here is my code:
!IF EXIST ("C:\ABC.XML")
#del ABC.XML
!ELSE
#echo "FILE DOESN'T EXIST
!ENDIF
The above code is not working. I could not figure it out the problem. Please help.
Your code doesn't work because !IF, !ELSE and !ENDIF are a preprocessing directives and the result of preprocessing must produce a valid makefile. Commands are only allowed as part of what Microsoft calls a description block which are required to start with a dependency line with one or more targets and zero or more dependents.
You can get around this by executing your commands during the preprocessing stage by including them in a preprocessing directive surrounded by brackets ([]). Something like this:
!IF EXIST(C:\ABC.XML)
! IF [del C:\ABC.XML]
! ENDIF
!ELSEIF [echo FILE DOESN'T EXIST]
!ENDIF
The second !IF and the !ELSEIF directives are used to provide a context for the commands so they're executed during the preprocessing phase.
However I think you'd probably be better moving the del command to a description block where it's actually needed. For example if file ABC.XML needs to be deleted before it can be rebuilt, use something like this:
ABC.XML: ABC.CSV
-rem The csv2xml translator requires that the XML file not already exist
-#del ABC.XML 2> NUL
csv2xml ABC.CSV ABC.XML

NSIS Invalid command: IDOK/IDCANCEL

I am able to use MessageBox MB_OK and MB_OKCANCEL, but compiler throws an error when I try to use IDOK and IDCANCEL.
My NSIS version is 2.46.
The basic syntax for calling MessageBox with OK and Cancel buttons is:
MessageBox MB_OKCANCEL "my message" IDOK label_for_ok IDCANCEL label_for_cancel
label_for_ok:
;do some stuff
goto end_label ;for not executing the "cancel" branch
label_for_cancel:
;do some other stuff
end_label:
In this case, as the ok case is just after the Messagebox, you can remove the IDOK label_for_ok and the label at the following line.
(Sorry for this little self promo)
You can use my tool called Visual & Installer (http://www.unsigned-softworks.sk/visual-installer/) to check correct syntax and usage in NSIS script in Visual Studio to avoid such situations:
As you can see it has a really nice syntax highlighting, when you move over some command a tooltip is shown and (if you look at Error List) you can see the PROGRAM_NAME was recognized as unused because it was not defined in the script snippet.

Exec not working in NSIS installer

I am new to NSIS i am trying to execute an executable while installation similar to pre request. I tried the below code which copies the exe to the installation path but it is not executing it.
Section "example" example
SetOutPath "$INSTDIR"
File "setup.exe"
Exec "$INSTDIR\setup.exe"
BringToFront
SectionEnd
The answer from Seki is mostly correct, I'd just like to add that the correct syntax for Exec/ExecWait is always Exec '"c:\path\app.exe" param1 "par am2" param3'
Parameters are of course optional but the path to the app should always be quoted, not just because in your case where $INSTDIR could contain spaces but at least on Win9x it will fail no matter what if you don't quote (According to the NSIS manual)
If the spaces/lack of quotes is not the issue then there are a couple of other things you might want to look into:
$OUTDIR is the working directory for the new process (SetOutPath sets this)
Missing dll's etc (Check with Process Monitor)
Do the $INSTDIR variable maps to a directory whose name contains spaces? If so, you should add simple quotes to include the double quotes into the Execargument :
Exec '"$INSTDIR\setup.exe"'

Resources