In NSIS is there a way to determine what version of windows the user is currently running?
The reason I want to do this is because my installer looks different on a Windows XP computer. My installer uses MUI2 but I dont seem to have the same GUI buttons(I think its called XP Style) as I do in Windows 7 and the main installer window is much larger than in Windows 7(where its about 500 by 400 pixels). Is it normal to a have these differences in an installer using MUI2? I thought MUI2 made the look consistant in windows versions XP and up?
To overcome the difference in installer window size, my solution is to detect if the user is using Windows XP and resize the window accordingly. Is this possible?
I need to have the window a specific size because I have a background image and the image is 500px wide so if the installer window is bigger I have a blank gap. I can change the background image to be wider but the easiest solution for myself is the one I explained above
In case Anders' answer is not explicit enough (took me a few hours to get it right), here is a more "beginner's friendly" version.
You will need to add !include WinVer.nsh to the top section of the cd.nsi file.
You then can use code like this:
${If} ${IsWinXP}
MessageBox MB_OK|MB_ICONEXCLAMATION "We have Win XP"
${EndIf}
This is the only function I tested, but the WinVer.nsh file starts with a mini-manual with its functions, which include:
AtLeastWin<version> which checks if the installer is running on Windows version at least as specified.
IsWin<version> which checks if the installer is running on Windows version exactly as specified.
AtMostWin<version> which checks if the installer is running on Windows version at most as specified.
<version> can be replaced with the following values (and maybe more, depending on how recent your WinVer.nsh file is): 95, 98, ME, NT4, 2000, XP, 2003, Vista, 2008, 7, 2008R2
There are some more functions and some usage examples in the WinVer.nsh file, which is probably located somewhere like C:\Program Files\NSIS\Include, like:
AtLeastServicePack which checks if the installer is running on Windows service pack version at least as specified.
IsServicePack which checks if the installer is running on Windows service pack version exactly as specified.
AtMostServicePack which checks if the installer is running on Windows service version pack at most as specified.
IsWin2003R2 (no more details supplied)
IsStarterEdition (no more details supplied)
OSHasMediaCenter (no more details supplied)
OSHasTabletSupport (no more details supplied)
MUI does not resize the window based on the Windows version. The window size is affected by the font and DPI settings however.
Use WinVer.nsh to detect the Windows version. This module is included in the NSIS includes folder by default.
The snippet bellow shows how to identify the Windows Version with as many detail as I could imagine to be useful:
!include WinVer.nsh
!include "LogicLib.nsh"
Function LogWinVer
${WinVerGetMajor} $R0
${WinVerGetMinor} $R1
${WinVerGetBuild} $R2
${WinVerGetServicePackLevel} $R3
; determine windows product name
${If} $R0 == 5
${If} $R1 == 0
DetailPrint "Windows 2000 SP $R3"
${ElseIf} $R1 == 1
DetailPrint "Windows XP SP $R3"
${ElseIf} $R1 == 2
DetailPrint "Windows Server 2003 SP $R3"
${EndIf}
${ElseIf} $R0 == 6
${If} $R1 == 0
${If} ${IsServerOS}
DetailPrint "Windows Server 2008 SP $R3"
${Else}
DetailPrint "Windows Vista SP $R3"
${EndIf}
${ElseIf} $R1 == 1
${If} ${IsServerOS}
DetailPrint "Windows Server 2008 R2 SP $R3"
${Else}
DetailPrint "Windows 7 SP $R3"
${EndIf}
${ElseIf} $R1 == 2
${If} ${IsServerOS}
DetailPrint "Windows Server 2012 SP $R3"
${Else}
DetailPrint "Windows 8 SP $R3"
${EndIf}
${ElseIf} $R1 == 3
${If} ${IsServerOS}
DetailPrint "Windows Server 2012 R2 SP $R3"
${Else}
DetailPrint "Windows 8.1 SP $R3"
${EndIf}
${EndIf}
${EndIf}
; version
DetailPrint "Kernel $R0.$R1 build $R2"
; x86 or x64:
Call LogWinVer
System::Call "kernel32::GetCurrentProcess() i .s"
System::Call "kernel32::IsWow64Process(i s, *i .r0)"
StrCmp $0 "0" is32bit is64bit
is32bit:
DetailPrint "32 bit"
Goto exit
is64bit:
DetailPrint "64 bit"
exit:
FunctionEnd
You could also read from the registry directly:
ReadRegStr $WinEdition HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" "ProductName"
Next, you can compare it using "==", for example:
${If} $WinEdition == "Windows XP"
or you could use StrContains to check if the windows version contains "Windows XP"
Related
I'm making a simple NSIS installator on Win 10 and I'm having some issues with a function ReadRegStr. ReadRegStr returns an empty string and sets a error flag which means the value could not be found. The value definitely exists (it was made by me) and is of a proper type REG_SZ.
The same behavior occurs even with SOME other keys:
HKLM SOFTWARE\FooBar (not working)
HKLM SOFTWARE\Docker Inc.\Docker\1.0 (not working)
HKLM SOFTWARE\Classes/.3gp (working)
HKCU Software\Python\PythonCore\3.6\InstallPath (working)
Powershell finds the values without any problems.
PS C:\Users\Admin\test> Get-ItemProperty -Path HKLM:\SOFTWARE\FooBar
(default) : fb
Here is a lightweight nsi script which I'm using
OutFile "Installer.exe"
Var FOO_VAR
!include LogicLib.nsh
Section
ReadRegStr $FOO_VAR HKLM "SOFTWARE\FooBar" ""
${If} ${Errors}
MessageBox MB_OK "Value not found"
${Else}
MessageBox MB_OK "FooBar $FOO_VAR"
${EndIf}
SectionEnd
All the keys above have at least read permission for every user/installer.
What else could be causing this?
64-bit Windows has two registry "views" and 32-bit applications see the 32-bit view by default. You can use the SetRegView instruction to force a 32-bit NSIS installer to use to the 64-bit view:
!include x64.nsh
!include LogicLib.nsh
Section
${If} ${RunningX64}
SetRegView 64
ReadRegStr ... value on 64-bit systems
SetRegView LastUsed
${Else}
ReadRegStr ... value on 32-bit systems
${EndIf}
SectionEnd
I have an NSIS script that has a show readme function that launches a pdf successfully in all OS's using the following line:
ExecShell "open" "$0\$(APP_DATA_PATH)\AppData\Readme\readme_$(LOCAL_CODE).pdf"
BUT - not in Windows 8. If any other reader other than Adobe is the default reader, it seems to be ok. We have to support Adobe and there seems to be nothing wrong with launching the pdf file elsewhere in Windows 8.
Is there any other NSIS command I can try to launch the file that I can try? Any other suggestions?
Try using the default verb: ExecShell "" "c:\full\path\to\file.pdf"
Edit:
Section
StrCpy $0 "$desktop\test.pdf"
; This should be the same as using ExecShell
System::Call 'shell32::ShellExecute(i$hwndparent,i0,t"$0",i0,i0,i5)i.r1'
DetailPrint "ShellExecute: Return=$1 (> 32 for success)"
; Let's try really hard by using SEE_MASK_INVOKEIDLIST
!define SEE_MASK_INVOKEIDLIST 0x0000000C
!define SEE_MASK_FLAG_DDEWAIT 0x00000100
System::Call '*(i60,i${SEE_MASK_INVOKEIDLIST}|${SEE_MASK_FLAG_DDEWAIT},i$hwndparent,i0,t"$0",i0,i0,i5,i,i0,i,i,i,i,i)i.r2' ; Allocate SHELLEXECUTEINFO
System::Call 'shell32::ShellExecuteEx(ir2)i.r1'
System::Free $2
DetailPrint "ShellExecuteEx: Success=$1"
SectionEnd
I want to create a dual installer for an application, which either installs it as portable or normal version.
For the portable version, I don't want to require admin rights. For the normal version, I need admin rights for adding the application to the start menu and other things.
Is there a way to prompt the user for admin rights when starting the actual installation? Maybe with a plug-in? I'm looking for something like RequestExecutionLevel admin inside a section.
RequestExecutionLevel highest will force members of the administrator group to elevate while normal users can run it with no UAC interaction. This example does not elevate for you because doing that is tricky, UAC is broken in certain scenarios and it would require more code to do it correctly...
RequestExecutionLevel highest
Var InstMode
!include nsDialogs.nsh
!include Sections.nsh
!include LogicLib.nsh
Page Custom InstallModePageInit InstallModePageLeave
Page InstFiles
Section "StartMenu shortcuts" SEC_SM
; CreateShortcut ...
SectionEnd
Section "" SEC_UNINST
; WriteUninstaller & registry
SectionEnd
Function InstallModePageInit
nsDialogs::Create 1018
Pop $0
${NSD_CreateRadioButton} 20u 30u 100% 12u "Normal install"
Pop $1
${NSD_CreateRadioButton} 20u 50u 100% 12u "Portable install"
Pop $2
${If} $InstMode = 0
${NSD_Check} $1
${Else}
${NSD_Check} $2
${EndIf}
nsDialogs::Show
FunctionEnd
Function InstallModePageLeave
${NSD_GetState} $2 $InstMode
${If} $InstMode = 0
!insertmacro SelectSection ${SEC_SM}
!insertmacro SelectSection ${SEC_UNINST}
UserInfo::GetAccountType
Pop $0
${If} $0 != "Admin"
MessageBox mb_iconstop "Administrator privileges required, please restart installer to continue..."
Abort
${EndIf}
${Else}
!insertmacro UnselectSection ${SEC_SM}
!insertmacro UnselectSection ${SEC_UNINST}
${EndIf}
FunctionEnd
I am newbie to nsis installer. I would like to detect the country of the user(via ip) and then depending on the country want to do some actions. I searched in nsis plugins directory but I found only a plugin to detect the ip.
How can I get the country code via ip in nsis ?
Thank you
Detecting country from IP means you need:
Internet connection
A way to determine the external IP (not counting proxies?)
Access to a IP/Geo database
Why not use the Windows configuration on the local machine:
!include LogicLib.nsh
!define LOCALE_SCOUNTRY 6 ; Localized
!define LOCALE_SENGCOUNTRY 4098
!define LOCALE_SENGLANGUAGE 0x00001001
!define GEOCLASS_NATION 16
!define GEOID_NOT_AVAILABLE -1
!define GEO_ISO2 4
!define GEO_ISO3 5
Section
System::Call 'KERNEL32::GetUserDefaultLangID()i.r0'
DetailPrint LANGID=$0
System::Call 'KERNEL32::GetLocaleInfo(i$0,i${LOCALE_SENGCOUNTRY},t.r1,i1000)'
DetailPrint LOCALE_SENGCOUNTRY=$1
System::Call 'KERNEL32::GetLocaleInfo(i$0,i${LOCALE_SCOUNTRY},t.r1,i1000)'
DetailPrint LOCALE_SCOUNTRY=$1
System::Call 'KERNEL32::GetLocaleInfo(i$0,i${LOCALE_SENGLANGUAGE},t.r1,i1000)'
DetailPrint LOCALE_SENGLANGUAGE=$1
System::Call 'KERNEL32::GetUserGeoID(i${GEOCLASS_NATION})i.r0'
DetailPrint GEOID=$0
${If} $0 <> ${GEOID_NOT_AVAILABLE} ; Only available if the user has set a country/location
${AndIf} $0 != "error" ; GetUserGeoID is WinXP+
System::Call 'KERNEL32::GetGeoInfo(i$0,i${GEO_ISO2},t.r1,i1000,i0)'
DetailPrint GEO_ISO2=$1
System::Call 'KERNEL32::GetGeoInfo(i$0,i${GEO_ISO3},t.r1,i1000,i0)'
DetailPrint GEO_ISO3=$1
${EndIf}
SectionEnd
So I'm trying to download and install PySVN as part of my program's stack. I'm downloading it rather than including, but the download is failing for unknown reasons. Here's the code:
!define PYSVN_FILE "py25-pysvn-svn161-1.7.0-1177.exe"
!define PYSVN_DOWNLOAD_LOC "http://pysvn.tigris.org/files/documents/1233/45661/py25-pysvn-svn161-1.7.0-1177.exe"
${If} $pythonVersion == "2.5"
NSISdl::download "${PYSVN_DOWNLOAD_LOC}" ${PYSVN_FILE}
${Else}
NSISdl::download "${PYSVN2_DOWNLOAD_LOC}" ${PYSVN_FILE}
${EndIf}
Where ${PYSVN_DOWNLOAD_LOC} = http://pysvn.tigris.org/files/documents/1233/45661/py25-pysvn-svn161-1.7.0-1177.exe is what I'm trying to download.
The file obviously downloads fine from a web browser, but NSIS throws a "connecting to host" error when it tries to connect. I've tried giving it a big timeout value. Is this a proxy issue? How can I get around this without including the file in my installer?
Edit:
Thanks to Anders I've edited my code as follows:
${If} $pythonVersion == "2.5"
inetc::get "${PYSVN_DOWNLOAD_LOC}" "${PYSVN_FILE}" /END
${Else}
inetc::get "${PYSVN2_DOWNLOAD_LOC}" "${PYSVN_FILE}" /END
${EndIf}
Which now gives me a "302 (redirection)" error. The file and download location have not changed.
NSISdl uses plain sockets and will fail if the server does redirect and cookie tricks/tracking, try INetC, it uses the higher level WinInet API
inetc::get /NOCANCEL /RESUME "" "http://file.blah" "$TEMP\Setup.exe"
Pop $0
StrCmp $0 "OK" dlok
MessageBox MB_OK|MB_ICONEXCLAMATION "Error downloading. Click OK to abort installation." /SD IDOK
dlok:
!insertmacro closeAllBrowsers
; install plugin
ExecWait `$TEMP\Setup.exe`