how to check software installed in NSIS? - nsis

i have created an installer using NSIS to install a software say googletalk in my system using following NSIS script ,
Name "installer"
OutFile "new_setup.exe"
InstallDir "$PROGRAMFILES\Google talk"
Section
SetOutPath $INSTDIR
execWait '$DESKTOP\googletalk-setup.exe'
SectionEnd
Now if i execute the installer once again, before installing it should check whether that software already exists or not.
So in NSIS how to achieve it ?.
Please tell me with code.
Thanks in advance!.

During installation, you need to create informations for uninstall in registry. (visible in Add/remove program on Windows control panel)
I advice you to follow this example :
http://nsis.sourceforge.net/Add_uninstall_information_to_Add/Remove_Programs
Then on your ".onInit" function, you just have to check these values with a ReadRegStr :
http://nsis.sourceforge.net/Docs/Chapter4.html#4.9.2.12
Hope this can help you.

Related

Electronjs - Delete registry entries when uninstalled

I need to delete Windows registry entries created by the application when the application is uninstalled.
The application is packed with electron-builder and i need to delete registry entries whether it is installed with .exe the with the windows store (appx)
What's the best way to accomplish this?
You can try to read this documentation https://www.electron.build/configuration/nsis.html.I am building an application with electron-builder too but I had not yet asked myself this problem. Thank you :)
" deleteAppDataOnUninstall = false Boolean - one-click installer only. Whether to delete app data on uninstall. "
you can add a custom nsis script in electron build. Use include option
https://www.electron.build/configuration/nsis.html#custom-nsis-script
then you can add below macro in the script file
!macro customUnInstall
DeleteRegValue HKLM "Software\Microsoft\Windows\CurrentVersion\Run"
"SomeLeafLevelEntry"
DeleteRegKey HKLM "SOFTWARE\XYZApp\AppTopLevelKey"
!macroend
that should delete the registry values
More info : https://nsis.sourceforge.io/Registry_plug-in#Delete_Registry_Key_.28same_as_DeleteRegKey.29
https://nsis-dev.github.io/NSIS-Forums/html/t-197518.html

NSIS Installer Run Batch File

Trying to run a batch file at the end of an installation, everything works great except this file won't run.
section "Startup"
Exec '"$0" /C "C:\Program Files\placeholder\startup\startup.bat"'
sectionEnd
Everything gets deposited in the right spot, using absolute pathing to call this. I asked for administrator privileges at the start,
RequestExecutionLevel admin ;Require admin rights on NT6+ (When UAC is turned on)
Just copying from the example NSIS installer provided here
The file is there so I must be making a mistake with the file path or missing some parameter. Been trying a lot of permutations like nsExec but not sure my mistake. Hopefully this is a simple mistake and will aid others in the same boat at some time.
Without more information I would guess that this is a 64-bit Windows machine and filesystem redirection is causing your 32-bit installer to access the wrong program files directory.
The code you posted is also problematic because we don't know what $0 is. I assume you failed to post the code where it expands %comspec%. To rule out this, replace $0 with $sysdir\cmd.exe.
Ideally your installer should extract the batch file to the destination directory:
Section
SetOutPath $InstDir
File batch.bat
ExecWait '"$sysdir\cmd.exe" /C if 1==1 "$InstDir\batch.bat"'
SectionEnd
If you must access the 64-bit folder you can disable the redirection but this is not recommended:
!include x64.nsh
Section
${DisableX64FSRedirection}
ExecWait ... $ProgramFiles64\...
${EnableX64FSRedirection}
SectionEnd
I think that you should give us more information to solve this problem.
Based on current information, I guess there are two reasons:
"C:\Program Files" is a path for 64-bit programs, but NSIS installer is a 32-bit program, so this path will be redirected to "C:\Program Files (x86)". You can use the solution from Anders to solve it.
Your batch file may contains relative paths. When you run your batch file from the NSIS installer, your working directory is not as same as your batch file. Due to this, some command cannot run correctly. You can use %~dp0 to solve it.

How can I create a single NSIS script which will generate different installers based on an input parameter?

I have an application which has development, testing and live versions. I have a command procedure which currently creates 3 different versions of the installer, which can be installed on 3 separate computers.
What I would like to do would be to have one NSIS script which I pass in a parameter to, which will create one of the versions of the installer changing the name of the product and the installation folder. This will allow me to install all 3 versions on the same computer.
What I have tried so far is;
Function .onInit
Var /GLOBAL INSTALL_TYPE
${GetOptions} $CMDLINE "/t" $INSTALL_TYPE
${if} $INSTALL_TYPE == ""
StrCpy $INSTALL_TYPE "Live"
ReadEnvStr $R0 SYSTEMDRIVE
StrCpy $INSTDIR "$LOCALAPPDATA\Programs\MyComp\MyApp$INSTALL_TYPE\"
FunctionEnd
!define MUI_PRODUCT "FCDS-RECAP$INSTALL_TYPE"
OutFile "MyApp-$INSTALL_TYPEinstaller.exe"
One of the main errors I get has to do with MUI_PRODUCT and look similar to;
warning 6000: unknown variable/constant "INSTALL_TYPE.lnk" detected, ignoring (FullDeploymentUser.nsi:121)
warning 6000: unknown variable/constant "INSTALL_TYPE" detected, ignoring (FullDeploymentUser.nsi:124)
Two types of comments would be useful;
This is what you are doing wrong...
This is what you should be doing...
As always any help is appreciated.
MUI_PRODUCT is technically not an official NSIS define, some guy just invented it and used it in a guide.
All instructions starting with ! are preprocessor instructions, those and OutFile and File cannot be controlled by ${GetOptions} because they happen at compile time on your developer machine.
I don't really recommend this 3 in 1 installer solution, it is a bit complicated. It is much better to just create 3 different installers:
!ifndef APPTYPE
!error "APPTYPE not defined"
!endif
Name "MyApp ${APPTYPE}"
OutFile "MyApp ${APPTYPE} setup.exe"
InstallDir "$ProgramFiles\MyApp ${APPTYPE}"
Page Directory
Page InstFiles
Section
SetOutPath $InstDir
File /r "c:\myfiles\MyApp\${APPTYPE}\*"
SectionEnd
and then just generate them with makensis -DAPPTYPE=Beta myapp.nsi etc.
If you really want this 3 in 1 style then you need to use the macros in Sections.nsh to manipulate the sections so that only one of them is visible and active. You also need to mark the install somehow (.ini file?) so that your uninstaller also knows which install type it is uninstalling.

using NISIS uninstaller to create an uninstaller

I am getting an error when I am trying to uninstall an application. I used NSIS to make installer and uninstaller for it. The application is uninstalled but it is not getting removed from the add/remove programs. the error looks like "an error occurred while trying to uninstall it may have already been uninstalled"
You need to delete the registry key relation to the Add/Remove Programs registration in your uninstall section.
See also the last paragraph of section "Required values" here.
For example, it could look like this:
Section Uninstall
; ...here the existing uninstall code goes...
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\WhateverNameYouHadUsedHereBefore"
SectionEnd

Folder in start menu/installation folder still exists,After uninstallation using NSIS script?

I have written nsis script for Java project.once i have clicked uninstaller.exe
Start menu >all programs >my application
all the files are removed successfully from location of installed.but the problem is, folder in STARTMENU/installation folder still exists,after clicking uninstallation.I dont know why this happened? I have used windows 7.
DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)"
Delete /REBOOTOK "$SMPROGRAMS\$StartMenuGroup\Uninstall $(^Name).lnk"
Delete /REBOOTOK $INSTDIR\uninstall.exe
I have used above code.Can anyone help me?
Where is the code to remove the directory? RMDir "$SMPROGRAMS\$StartMenuGroup"
It is also important to use RequestExecutionLevel so you don't run into compatibility issues...

Resources