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`
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
Trying to use an NSI script that works with 2.46 Unicode, in the new version 3, this line:
!insertmacro UAC_AsUser_ExecShell '' '$INSTDIR\test.exe' '--openbrowser' '' SW_SHOWNORMAL
produces the following error:
!undef: "_UAC_ParseDefineFlags_orin_f2" not defined!
Error in macro _UAC_ParseDefineFlags_orin on macroline 12
Error in macro _UAC_ParseDefineFlags_Begin on macroline 6
Error in macro _UAC_ParseDefineFlagsToInt on macroline 1
Error in macro UAC_AsUser_Call on macroline 5
Error in macro UAC_AsUser_ExecShell on macroline 11
Error in script "c:\my.nsi" on line 308 -- aborting creation process
There is a similar, unanswered question, back from a year ago.
My question:
How to use the UAC plug-in with NSIS 3?
Using UAC plug-in v0.2.4c (20150526) from the wiki I can't reproduce your error with a simple clone of UAC_Basic.nsi in NSIS v3.01:
Unicode true
!addplugindir ".\plugins\x86-unicode" ; Only required if you have not copied the .dll
!define S_NAME "UAC minimal test ${NSIS_PACKEDVERSION}"
Name "${S_NAME}"
OutFile "${S_NAME}.exe"
RequestExecutionLevel user ; << Required, you cannot use admin!
InstallDir "$ProgramFiles\${S_NAME}"
!include UAC.nsh
!include MUI2.nsh
!macro Init thing
uac_tryagain:
!insertmacro UAC_RunElevated
${Switch} $0
${Case} 0
${IfThen} $1 = 1 ${|} Quit ${|} ;we are the outer process, the inner process has done its work, we are done
${IfThen} $3 <> 0 ${|} ${Break} ${|} ;we are admin, let the show go on
${If} $1 = 3 ;RunAs completed successfully, but with a non-admin user
MessageBox mb_YesNo|mb_IconExclamation|mb_TopMost|mb_SetForeground "This ${thing} requires admin privileges, try again" /SD IDNO IDYES uac_tryagain IDNO 0
${EndIf}
;fall-through and die
${Case} 1223
MessageBox mb_IconStop|mb_TopMost|mb_SetForeground "This ${thing} requires admin privileges, aborting!"
Quit
${Case} 1062
MessageBox mb_IconStop|mb_TopMost|mb_SetForeground "Logon service not running, aborting!"
Quit
${Default}
MessageBox mb_IconStop|mb_TopMost|mb_SetForeground "Unable to elevate , error $0"
Quit
${EndSwitch}
SetShellVarContext all
!macroend
Function .onInit
!insertmacro Init "installer"
FunctionEnd
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!define MUI_FINISHPAGE_RUN
!define MUI_FINISHPAGE_RUN_FUNCTION PageFinishRun
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_LANGUAGE "English"
Section
SectionEnd
Function PageFinishRun
!insertmacro UAC_AsUser_ExecShell '' '$WinDir\notepad.exe' '--openbrowser' '' SW_SHOWNORMAL
FunctionEnd
Digging an old thread:
I had the same problem, the UAC plugin on wiki has a small change compared to the version I was using with NSIS 2.x.
That small change fixed the issue
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
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"
I need NSIS script witch download file from the internet and execute it.
I've read many examples but I still don't understand how to do it. For example
NSISdl::download http://www.domain.com/file localfile.exe
Pop $R0 ;Get the return value
StrCmp $R0 "success" +3
MessageBox MB_OK "Download Failed: $R0"
Quit
$R0 contains information about installation process ("cancel" or "success"). But I don't understand what the "localfile.exe" is?
In what part of program I need write this code(section or function)?
localfile.exe is the path on the local system where you want to save the content you are downloading:
!include LogicLib.nsh
Section
NSISdl::download "http://cdn.sstatic.net/stackoverflow/img/sprites.png" "$pluginsdir\image.png"
Pop $0
${If} $0 == "success"
ExecShell "" '"$pluginsdir\image.png"' ;Open image in default application
${Else}
MessageBox mb_iconstop "Error: $0" ;Show cancel/error message
${EndIf}
SectionEnd