I have an NSIS installer set to run in silent mode. This works very well.
I've had a customer request for an informational pop up once the install has complete...but still wants the installer portion to be silent!
I realize this is counter intuitive.
That being said is there away to override the silent at the end of the install?
I currently set the installer attribute below at the beginning of the .nsi script
SilentInstall silent
You can toggle silent mode on or off in .onInit with SetSilent but once that function returns the UI mode cannot be changed.
The simple solution is to simply use one of the Banner or Splash plug-ins at the end of your last Section to display a message/image.
Or you can create a fake silent mode with a minimal UI that only displays the progress bar:
!include LogicLib.nsh
Var Silent
Function .onInit
${If} ${Silent}
SetSilent Normal ; Turn off real silent mode
SetAutoClose True
StrCpy $Silent 1 ; Fake silent mode
${EndIf}
FunctionEnd
Page Components SkipPageIfSilent
Page Directory SkipPageIfSilent
Page InstFiles "" TweakInstfilesPage
Function SkipPageIfSilent
IntCmp $Silent 0 +2
Abort
FunctionEnd
Function TweakInstfilesPage
${If} $Silent <> 0
SetSilent Silent ; Make IfSilent return true
FindWindow $0 "#32770" "" $HWNDPARENT
GetDlgItem $0 $0 0x403 ; Show details button
ShowWindow $0 0
System::Call 'USER32::GetWindowRect(p$0,#r1)' ; NSIS v3+
System::Call 'USER32::GetWindowRect(p$HWNDPARENT,#r2)' ; NSIS v3+
System::Call '*$1(i,i.r3,i,i)'
System::Call '*$2(i.r5,i.r6,i.r7,ir3r8)'
IntOp $5 $7 - $5 ; Width
IntOp $6 $8 - $6 ; Height
System::Call 'USER32::SetWindowPos(p$HWNDPARENT,p,i,i,ir5,ir6,i0x12)'
SetDetailsView Hide
${EndIf}
FunctionEnd
Section
Sleep 333
Sleep 333
Sleep 333
Sleep 333
SectionEnd
Related
I'm using WindowsXP, NSIS 2.46 with nsSCM plug-in, and have 4 machines with nearly the same environment(hardware + software) since they come from a same GHOST image but with very limited changes on application layer(no any system settings changed).
I'm using NSIS installer to install my application to them, detail process are:
Stop 'Apache2.2' service.
Copy files to Apache root folder.
CreateShortCut
With script:
CreateShortCut "$SMPROGRAMS\MyApp\Stop.lnk" "$SYSDIR\sc.exe" "stop MyAppService" "C:\WINDOWS\system32\SHELL32.dll" 27 SW_SHOWMINIMIZED
CreateShortCut "$SMPROGRAMS\MyApp\ShowDemo.lnk" "$PROGRAMFILES\MyAppPath\MyAppShowDemoHelper.exe" "-b 102" "C:\WINDOWS\system32\SHELL32.dll" 24 SW_SHOWMINIMIZED
Start 'Apache2.2' service.
With script:
nsSCM::Start /NOUNLOAD "Apache2.2"
Pop $0 ; return error/success
${If} $0 == "success"
MessageBox MB_ICONINFORMATION|MB_OK "Successfully started 'Apache2.2' service"
${Else}
MessageBox MB_ICONSTOP|MB_OK "Failed to start 'Apache2.2' service with result: $0, Contact help desk or start it manually!"
${EndIf}
===========================
Now the problem is the step 4, in two of those machines, it always popup ERROR and always need manually to start the service(with no error), but meantime, the shortcuts are created successfully.
I've checked system logs, Apache logs, but no error logs/message could be found.
I spend one day and tried everything, at last, I found once I remove the Step 3, everything is fine, so any idea Why?
[Edit0]:
For work around, I have to switch Step 3 and 4, at least now it works good.
CreateShortcut should have no impact on plugins so this is rather strange. It would be nice if we could narrow this down to a problem with the plugin API in NSIS or a problem in the plugin itself. Maybe you could try the SimpleSC plugin?
Here is some code that does it manually with the system plugin. It is not pretty but should display a relevant error code if it fails.
Section
!define MyServiceName "Spooler" ;"stisvc"
ExecWait '"$SysDir\cmd.exe" /c net stop "${MyServiceName}"' ; Hack to make sure the service is stopped so we can try starting it again
Sleep 1111
InitPluginsDir
CreateShortcut "$PluginsDir\Test1.lnk" "$ExePath" ; Create some dummy shortcuts to possibly trigger the bug
CreateShortcut "$PluginsDir\Test2.lnk" "$ExePath"
!include LogicLib.nsh
!include Util.nsh
!define ERROR_SERVICE_ALREADY_RUNNING 1056
!define SC_MANAGER_CONNECT 0x0001
!define SERVICE_QUERY_STATUS 0x0004
!define SERVICE_START 0x0010
!define SERVICE_PAUSE_CONTINUE 0x0040
!define SERVICE_CONTROL_CONTINUE 3
!define SERVICE_STOPPED 1
!define SERVICE_START_PENDING 2
!define SERVICE_STOP_PENDING 3
!define SERVICE_RUNNING 4
!define SERVICE_CONTINUE_PENDING 5
!define SERVICE_PAUSE_PENDING 6
!define SERVICE_PAUSED 7
!macro WaitForServiceRunningStatus_
System::Store S
Pop $6
Pop $1
System::Call KERNEL32::GetTickCount()i.r7
System::Call '*(i,i,i,i,i,i,i)i.r2'
loop:
System::Call 'ADVAPI32::QueryServiceStatus(ir1, ir2)i.r3'
System::Call '*$2(i,i.r4)'
${If} $3 <> 0
${If} $4 = ${SERVICE_RUNNING}
DetailPrint 'Service is now running.'
${Else}
Sleep 250
System::Call KERNEL32::GetTickCount()i.r8
${IfThen} $8 < $7 ${|} StrCpy $7 $8 ${|} ; Reset on GetTickCount rollover
IntOp $8 $8 - $7
IntCmpU $8 $6 "" loop
DetailPrint 'Timeout! Service status is $4'
${EndIf}
${EndIf}
System::Free $2
System::Store L
!macroend
!macro WaitForServiceRunningStatus hSC MsTimeout
Push ${hSC}
Push ${MsTimeout}
${CallArtificialFunction} WaitForServiceRunningStatus_
!macroend
System::Call 'ADVAPI32::OpenSCManager(t"", i0, i${SC_MANAGER_CONNECT})i.r0 ?e'
Pop $9
${If} $0 = 0
DetailPrint 'OpenSCManager(t"", i0, i${SC_MANAGER_CONNECT}) failed with error $9'
${Else}
System::Call 'ADVAPI32::OpenService(ir0, t"${MyServiceName}", i${SERVICE_QUERY_STATUS}|${SERVICE_START}|${SERVICE_PAUSE_CONTINUE})i.r1 ?e'
Pop $9
${If} $1 = 0
DetailPrint 'OpenService("${MyServiceName}") failed with error $9'
${Else}
System::Call '*(i,i,i,i,i,i,i)i.r2'
System::Call 'ADVAPI32::QueryServiceStatus(ir1, ir2)i.r3 ?e'
Pop $9
${If} $3 = 0
DetailPrint 'QueryServiceStatus failed with error $9'
StrCpy $4 0 ; We failed, set to unused code so we stop processing
${Else}
System::Call '*$2(i.r3,i.r4,i.r5,i,i,i,i)'
IntFmt $3 "%#x" $3
IntFmt $4 "%#x" $4
IntFmt $5 "%#x" $5
DetailPrint 'QueryServiceStatus: Type=$3, CurrentState=$4 ControlsAccepted=$5'
${EndIf}
${If} $4 = ${SERVICE_PAUSE_PENDING}
${OrIf} $4 = ${SERVICE_PAUSED}
System::Call 'ADVAPI32::ControlService(ir1, i${SERVICE_CONTROL_CONTINUE}, ir2)i.r3 ?e'
Pop $9
${If} $3 = 0
DetailPrint 'ControlService(SERVICE_CONTROL_CONTINUE) failed with error $9'
${Else}
DetailPrint 'Resuming "${MyServiceName}"...'
!insertmacro WaitForServiceRunningStatus $1 5000
${EndIf}
${ElseIf} $4 = ${SERVICE_CONTINUE_PENDING}
!insertmacro WaitForServiceRunningStatus $1 5000
${ElseIf} $4 >= ${SERVICE_STOPPED}
${If} $4 = ${SERVICE_RUNNING}
DetailPrint "Service already running"
${Else}
System::Call 'ADVAPI32::StartService(ir1, i0, i0)i.r3 ?e'
Pop $9
${If} $3 = 0
DetailPrint 'StartService failed with error $9'
${Else}
DetailPrint 'Starting "${MyServiceName}"...'
!insertmacro WaitForServiceRunningStatus $1 9000
${EndIf}
${EndIf}
${EndIf}
System::Free $2
System::Call 'ADVAPI32::CloseServiceHandle(i.r1)'
${EndIf}
System::Call 'ADVAPI32::CloseServiceHandle(i.r0)'
${EndIf}
SectionEnd
I run a certain process via ExecShell from my NSIS installer. That process takes sometime to start (5 - 40 seconds maybe), during which I want the NSIS window to remain visible.
The problem is that while the process itself starts almost instantly, it is sometime before a user would see anything, thus I want the NSIS installer window to remain visible UNTIL the started process's main window (or any window for that matter is shown).
What I need to know thus is how do I get processid from ExecShell (can't use Exec or ExecWait for other reasons), and then how do I use that process id to see if the window has been shown (I know I can do it via a simple sleep, check, goto loop, so basically I am trying to figure out the check part of it)?
So, how exactly can I know if the process I spawned using ShellExec has shown a GUI. This needs to work in Windows XP SP3 and up.
Thank you.
RequestExecutionLevel user
Page InstFiles
!include LogicLib.nsh
!include WinMessages.nsh ; For SW_*
Var IsSlowFakeApp ; We can also pretend to be a silly little app that is slow to start up, this is just so the example code has no external dependencies
Function .onInit
StrCpy $0 $CMDLINE 1 -1
${If} $0 == "?"
StrCpy $IsSlowFakeApp 1
Sleep 3333
${EndIf}
FunctionEnd
Function StartMyAppAndWaitForWindow
StrCpy $0 "$ExePath" ; Application
StrCpy $1 "?" ; Parameters
!define SEE_MASK_NOCLOSEPROCESS 0x40
DetailPrint 'Starting "$0" $1'
System::Store S
System::Call '*(i60,i${SEE_MASK_NOCLOSEPROCESS},i$hwndparent,i0,tr0,tr1,i0,i${SW_SHOW},i,i,i,i,i,i,i)i.r0'
System::Call 'SHELL32::ShellExecuteEx(ir0)i.r1'
${If} $1 <> 0
System::Call '*$0(i,i,i,i,i,i,i,i,i,i,i,i,i,i,i.r1)'
System::Call 'USER32::WaitForInputIdle(ir1,2000)i'
System::Call 'KERNEL32::GetProcessId(ir1)i.r2' ; MSDN says this function is XP.SP1+
StrCpy $3 $2 ; Not found a window yet, keep looping
; Call EnumWindows until we find a window matching our target process id in $2
System::Get '(i.r5, i) iss'
Pop $R0
callEnumWindows:
System::Call 'USER32::EnumWindows(k R0, i) i.s'
loopEnumWindows:
Pop $4
StrCmp $4 "callback1" 0 doneEnumWindows
System::Call 'USER32::GetWindowThreadProcessId(ir5,*i0r4)'
${If} $4 = $2
System::Call 'USER32::IsWindowVisible(ir5)i.r4'
${IfThen} $4 <> 0 ${|} StrCpy $3 0 ${|} ; Found a visible Window
${EndIf}
Push $3 ; EnumWindows callback's return value
System::Call "$R0"
Goto loopEnumWindows
doneEnumWindows:
${If} $3 <> 0
Sleep 1000
Goto callEnumWindows
${EndIf}
System::Free $R0
; Hide installer while app runs
/*HideWindow
System::Call 'KERNEL32::WaitForSingleObject(ir1,i-1)'
BringToFront*/
System::Call 'KERNEL32::CloseHandle(ir1)'
${EndIf}
System::Free $0
System::Store L
FunctionEnd
Section
${If} $IsSlowFakeApp <> 0
SetCtlColors $HWNDPARENT 0xffffff 0xdd0000
FindWindow $0 "#32770" "" $HWNDPARENT
SetCtlColors $0 0xffffff 0xdd0000
DetailPrint "This is a fake slow app and it will close soon..."
Sleep 5555
Quit
${Else}
Call StartMyAppAndWaitForWindow
${EndIf}
SectionEnd
I am wondering if it will be possible to perform the following UI modifications / tweaks (programmatically in the nsi script) WHILE the installation is running on the MUI_PAGE_INSTFILES page:
Set the style of the progress bar to marque (continuous "scrolling")
Hide the details text field (where the progress text is displayed) and show a predefined picture instead (that was included with the setup)
[EDIT] Alternatively for number 2: maybe shrink the details field, and display the picture as a banner like label just below it (so that the details field would occupy only half the space vertically, and the other half below it would be used by the picture - that way a user can see both the progress and the "banner").
[EDIT] Even better still would be to have some sort of basic slide show: define several pictures and rotate them every 10 seconds
The idea behind this is that during parts of the installation that may take some time (say over 10 seconds) to display something more informative / valuable to the user, such as how to get started graphic, a sales promotion or something else.
How can this be done?
Thanks.
XPStyle on ; This must be on for the Marquee to show
!include nsDialogs.nsh ; For WS_* and NSD_SetImage
!include WinMessages.nsh
!ifndef PBS_MARQUEE
!define PBS_MARQUEE 8
!endif
!ifndef PBM_SETMARQUEE
!define PBM_SETMARQUEE 0x40A
!endif
!macro ProgressMarquee_Begin
FindWindow $0 "#32770" "" $HWNDPARENT ; Find inner dialog
GetDlgItem $0 $0 1004 ; Find progress-bar
System::Call USER32::GetWindowLong(ir0,i-16)i.r1
IntOp $1 $1 | ${PBS_MARQUEE}
System::Call USER32::SetWindowLong(ir0s,i-16,ir1s) ; This also saves the handle and style on the stack, we need those to turn it off again.
SendMessage $0 ${PBM_SETMARQUEE} 1 0 ; The last parameter is the speed or 0 for the default
!macroend
!macro ProgressMarquee_Remove
Exch
Pop $1
IntOp $0 ${PBS_MARQUEE} ~
IntOp $1 $1 & $0
System::Call USER32::SetWindowLong(is,i-16,ir1)
!macroend
Function DoLongOperation
DetailPrint "Starting long operation"
Sleep 4444
DetailPrint "Long operation ended..."
FunctionEnd
Section
DetailPrint "Simulating other install tasks..."
Sleep 222
Sleep 222
Sleep 222
Sleep 222
Sleep 222
Sleep 222
; Add a image and hide the log
FindWindow $2 "#32770" "" $HWNDPARENT ; Find inner dialog
GetDlgItem $0 $2 0x3F8 ; Find log window
System::Call *(i,i,i,i)i.r1 ; Allocate a RECT
System::Call 'USER32::GetWindowRect(ir0s,ir1)' ; Also saves log HWND on stack
ShowWindow $0 0 ; Hide log window
System::Call '*$1(i.r4,i.r5,i.r6,i.r7)'
IntOp $6 $6 - $4
IntOp $7 $7 - $5
System::Call 'USER32::ScreenToClient(ir2,ir1)'
System::Call '*$1(i.r4,i.r5)'
System::Free $1
System::Call 'USER32::CreateWindowEx(i0,t"STATIC",i0,i${WS_CHILD}|${WS_CLIPSIBLINGS}|${WS_VISIBLE}|${SS_BITMAP},ir4,ir5,ir6,ir7,ir2,i0,i0,i0)i.r2'
Push $2 ; Save HWND
SetDetailsPrint none
File "/oname=$pluginsdir\img.bmp" "${NSISDIR}\Contrib\Graphics\Header\orange.bmp"
SetDetailsPrint lastused
${NSD_SetImage} $2 "$pluginsdir\img.bmp" $9
Push $9 ; Save HBITMAP
!insertmacro ProgressMarquee_Begin
Call DoLongOperation
!insertmacro ProgressMarquee_Remove
; Remove and cleanup image
Pop $0
${NSD_FreeBitmap} $0
Pop $0
ShowWindow $0 0
Pop $0 ; Log window handle we saved
ShowWindow $0 1
SectionEnd
If you want to show multiple images then you need multiple calls to ${NSD_SetImage} but if you want to go down this route it is probably much better to write a NSIS plugin that does all this on a secondary thread...
My goal is to know if you use any check or code snipp to determine if ther is some dependecy when passing NSIS command line params to copiled setup using Silent installation ( /S param ).
The NSIS sample: http://nsis.sourceforge.net/Get_command_line_parameter_by_name
For example, If I have three params: Setup.exe /S param1="" param2="" param3=""
How to check the following secanrio:
${if} <Param1 is passed to Setup.exe>
<Param2 must ALSO be passed to Setup.exe>
${else}
<Error message notifiing that Param1 is present, but dependent Param2 param is missing in CMD parameters>
Thank you!
I really hope you will share at least code snipp ... if not whole functional code.
outfile test.exe
requestexecutionlevel user
silentinstall silent ;always force silent in this sample
!include LogicLib.nsh
!include FileFunc.nsh
Function StripOptPrefix
Exch $0
Push $1
StrCpy $1 $0 1
${If} $1 == "="
${OrIf} $1 == ":"
StrCpy $0 $0 "" 1
${EndIf}
Pop $1
Exch $0
FunctionEnd
!macro StripOptPrefix var
Push ${var}
call StripOptPrefix
Pop ${var}
!macroend
Section
${GetParameters} $0
${If} $0 == ""
;No parameters, lets run the tests
ExecWait '"$exepath" /param1=foo'
ExecWait '"$exepath" /param1=foo /param2=bar'
${Else}
${GetOptions} $0 "/param1" $1
${If} ${Errors}
# /param 1 not used, do nothing?
${Else}
${GetOptions} $0 "/param2" $2
${If} ${Errors}
MessageBox mb_iconstop "Missing /param2, required by /param1"
Quit
${Else}
!insertmacro StripOptPrefix $1
!insertmacro StripOptPrefix $2
MessageBox mb_ok "1=$1$\n2=$2"
${EndIf}
${EndIf}
${EndIf}
SectionEnd
I'm using NSIS 2.46 to create a installer for my windows application, I have a component page with 12 checkboxes, that is 12 sections in my NSIS code, now I want to disable the 'Next' button if none of the sections are checked by the user, I'm using this code:
Somehow it doesn't accept R registers above R9...
SectionGetFlags ${section11} $R10
SectionGetFlags ${section12} $R11
The compiler error I'm getting is
Please tell me how to disable the 'Next' button if there are more than 10 components...
The basic NSIS registers are $0...$9 and $R0...$R9, so you should use $1 and $2 for the last two sections. Or you can create more variables if you want; Var /GLOBAL R10.
If section1 to section12 are numbered without gaps you can use a loop:
!include LogicLib.nsh
Section A S_1
SectionEnd
Section /o B S_2
SectionEnd
Section C S_3
SectionEnd
Function .onSelChange
StrCpy $0 0
StrCpy $1 ${S_1}
${DoWhile} $1 <= ${S_3}
${If} ${SectionIsSelected} $1
StrCpy $0 1
${ExitDo}
${EndIf}
IntOp $1 $1 + 1
${Loop}
GetDlgItem $1 $HwndParent 1
EnableWindow $1 $0
FunctionEnd