Archive: Silent uninstall will not abort if application is in use


Silent uninstall will not abort if application is in use
I have an uninstaller that checks whether the application it is removing is currently in use (Using iceman_k's "FindProc" plugin), and is supposed to abort if it is.

When running the uninstaller normally, a custom page is displayed (Using the MUI) informing the user that they need to exit the application before continuing. This works as expected.

However, if the uninstaller is run silently, it should abort during the initialization phase. This is NOT working as expected. Every time I run the uninstaller silently, it will continue with the uninstallation process regardless of whether the application is currently in use or not.

The following is a simplified version of my uninstaller:


!insertmacro MUI_UNPAGE_WELCOME
UninstPage CUSTOM un.ApplicationInUse_EnterPage un.ApplicationInUse_ExitPage
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH


Section "Uninstall"
; These instructions are reused by "onInstFailed"
!include "Uninstallation.nsi"

SetAutoClose TRUE
SectionEnd


Function un.onInit
IfSilent +3 0
!insertmacro MUI_INSTALLOPTIONS_EXTRACT "CustomPage.ini"
GoTo End

FindProcDLL::FindProc "MyApplication.exe"
Pop $R0
${If} $R0 == 1
Abort
${EndIf}

End:
FunctionEnd


Function un.ApplicationInUse_EnterPage
FindProcDLL::FindProc "MyApplication.exe"
Pop $R0

${If} $R0 == 1
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "CustomPage.ini"
${EndIf}
FunctionEnd


Function un.ApplicationInUse_ExitPage
Quit
FunctionEnd


Note that the "FindProc" call only returns a value of "1" if the application can definitely be determined to be in use.

So, the question is, what's the problem? The script being used in the "un.onInit" and "un.ApplicationInUse_EnterPage" functions is the same, yet only the latter works as expected.

The code as it appears here seems correct.
Did you try to debug the silent return of FindProcDll with a message box? e.g.

Function un.onInit
IfSilent 0 end
FindProcDLL::FindProc "MyApplication.exe"
Pop $R0
MessageBox MB_OK '$$R0 == {$R0}'
${If} $R0 == 1
Abort
${EndIf}
End:
FunctionEnd


Originally posted by Red Wine
Did you try to debug the silent return of FindProcDll with a message box?
I was of the belief that MessageBoxes didn't display in Silent mode, and since no MessageBox was displayed when I tested your suggestion code, it looks like I may have been right... ;)

Should the MessageBox be displayed when Silent mode is on, or is there another (Preferrably easy) way of outputting debug information?

Either way, I would hope that the plugin should behave the same way regardless of the uninstaller's "silence". I can't think of any reason why it shouldn't...?

This doesn't work for you?

OutFile 'test.exe'

Section "boo"
call func
SectionEnd

function func
IfSilent +1 +2
Messagebox MB_OK 'We re running silent' idok end
Messagebox MB_OK 'poof'
end:
functionend

function .onInit
SetSilent silent
functionend


is there another (Preferrably easy) way of outputting debug information?
Function un.onInit
FileOpen $0 '$EXEDIR\debug.txt' w
IfSilent 0 end
FindProcDLL::FindProc "MyApplication.exe"
Pop $R0
;MessageBox MB_OK '$$R0 == {$R0}'
FileWrite $0 'We re running silent$\r$\n'
FileWrite $0 '$$R0 == {$R0}$\n$\n'
FileClose $0
ExecShell open '$EXEDIR\debug.txt'
${If} $R0 == 1
Abort
${EndIf}
End:
FileWrite $0 'We re NOT running silent'
FileClose $0
ExecShell open '$EXEDIR\debug.txt'
FunctionEnd

Previous attempts to make a MessageBox appear when running in Silent mode did not work, but recent ones did, so I'll lump that in with the other great mysteries of life for the time-being.

When I did eventually get my MessageBox, it indicated that the plugin was working as expected, so I started looking at other things.

One small change I tried, was changing the label used to direct program execution when it was determined that the uninstaller was running in Silent mode. Instead of a "+3", to skip over the extraction of a custom GUI page, I created a label just before the start of the "Silent mode" script, and explicitly named it. Strangely enough, it worked perfectly!

So, by changing the "un.onInit" function to this...


Function un.onInit
IfSilent SilentMode 0
!insertmacro MUI_INSTALLOPTIONS_EXTRACT "CustomPage.ini"
GoTo End

SilentMode:
FindProcDLL::FindProc "MyApplication.exe"
Pop $R0
${If} $R0 == 1
Abort
${EndIf}

End:
FunctionEnd


...I got it working the way I had expected it to all along.

I have to admit that I've occassionally run into issues with numbered labels like this before, but this one definitely looked like it should have worked... Oh well.

Thankyou very much for your help anyway.

You're welcome!
You may want to refer to NSIS manual 4.9.4.15 MessageBox,
or accept living the life with those great "mysteries". :-)
BTW while studying the manual, you'll find useful info regarding to labels and relative jumps (numbered labels) :-)