Old 28th June 2010, 14:27   #1
nsnb
Senior Member
 
Join Date: Jul 2008
Posts: 157
Question ExecWait doesn't wait (on Windows 7)

I came across this problem while testing the uninstall part of an NSIS script:

Despite not changing anything in the -un.post section that takes care of removing all Start Menu entries:
PHP Code:
  ;Delete empty start menu parent diretories
  StrCpy $MUI_TEMP 
"${D_STARTMENU}"
SMDELOOP:
    
ClearErrors
    RMDir $MUI_TEMP
    GetFullPathName $MUI_TEMP 
"$MUI_TEMP\.."
    
IfErrors SMDELDONE
    StrCmp $MUI_TEMP $SMPROGRAMS SMDELDONE SMDELOOP
SMDELDONE

The uninstaller no longer deletes the last (topmost) entry in the Start Menu. In my attempts to troubleshoot this I discovered that this is not always consistent: Sometimes it deletes and sometimes it doesn't.

So, I decided to place a MessageBox line right after the 'RMDir $MUI_TEMP' line:
PHP Code:
    RMDir $MUI_TEMP
MessageBox MB_OK
|MB_ICONEXCLAMATION "Removed $MUI_TEMP"    ; for debug only
    GetFullPathName $MUI_TEMP 
"$MUI_TEMP\.." 
And I was surprised to see that this message box is displayed while an ExecWait from a previous un.Uninstall section was still in progress...
PHP Code:
ExecWait '"$INSTDIR\vcredist_x86.exe" /q:a /c:"VCREDI~1.EXE /q:a /c:""msiexec /x vcredist.msi /qb!"" "' 
Obviously, something is happening here in parallel but how could this be?
  1. Isn't ExecWait supposed to wait?
  2. Isn't Section -un.post supposed to start after all Section "un.Uninstall"s?

Most importantly: How would you suggest that I solve (or workaround) this problem?

Thanks!
nsnb is offline   Reply With Quote
Old 28th June 2010, 14:55   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,181
ExecWait ALWAYS waits, I have not seen a single case yet where it is actually broken (and it will probably never happen, it is just WaitForSingleObject on a process handle) If you think it does not wait, the command you are executing is probably wrong (Or it spawns subprocesses and has no option to wait on them)

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 28th June 2010, 17:03   #3
thek
Member
 
thek's Avatar
 
Join Date: Jun 2006
Location: Austria
Posts: 92
Hello nsnb

Anders is right with is assumption, vc_redist spawns his own process
actually I don't understand what you try to achieve with your command
with your command you decompress the contents of vc_redist, there you start again a vc_redist where you decompress the contents and start the MSI installer!!!

so there are probably 3 childprocess spawend!
I simply use '"$TEMP\VS2008_SP1_vcredist_x86.exe" /q'

if a real feedback for the user is needed you should install the redistributable files manually
decompress the content and add it file by file to your installer.


Also I wouldn't uninstall the VC redist
Because other programms installed after your application my depend on it!!
so your uninstaller will probably break other apps!

Last edited by thek; 28th June 2010 at 17:07. Reason: further information found
thek is offline   Reply With Quote
Old 28th June 2010, 17:58   #4
nsnb
Senior Member
 
Join Date: Jul 2008
Posts: 157
Lightbulb

Thank you Anders and thek for your answers.

Quote:
Originally Posted by thek View Post
I don't understand what you try to achieve with your command... you should install the redistributable files manually decompress the content and add it file by file to your installer.
It's a legal issue dictated by Microsoft's EULA.

After experimenting with this a little more, I discovered that the MessageBox actually solves the problem... This is not practical of course for the real installer, so I wonder what types of workarounds can I come up with?

Perhaps placing a delay of several hundreds milliseconds?
nsnb is offline   Reply With Quote
Old 28th June 2010, 18:38   #5
nsnb
Senior Member
 
Join Date: Jul 2008
Posts: 157
Lightbulb

Quote:
Originally Posted by nsnb View Post
so I wonder what types of workarounds can I come up with? Perhaps placing a delay of several hundreds milliseconds?
Answering myself: Sleep() is ugly (in any programming language...), so I took the asynchronous approach: Right after the RMDir $MUI_TEMP line I check for errors:
PHP Code:
RMDir $MUI_TEMP
IfErrors L_SM_ERROR
...
...
...
L_SM_ERROR:
MessageBox MB_OK|MB_ICONEXCLAMATION "Error in RMDir $MUI_TEMP." 
It turns out that by mere checking for the error, it never occurs anymore... (the message box is never displayed and the entire Start Menu entry is removed cleanly just as it used to be).

Suggests a timing problem?
nsnb is offline   Reply With Quote
Old 28th June 2010, 18:47   #6
CrushBug
Senior Member
 
Join Date: May 2005
Posts: 119
We have unpacked the vcredist.msi and vcredist.cab files and ExecWait the following:

vcredist.msi /passive /norestart

That works for us.
CrushBug is offline   Reply With Quote
Old 29th June 2010, 17:25   #7
nsnb
Senior Member
 
Join Date: Jul 2008
Posts: 157
Exclamation

Quote:
Originally Posted by CrushBug View Post
We have unpacked the vcredist.msi and vcredist.cab files and ExecWait the following:

vcredist.msi /passive /norestart

That works for us.
Of course it works but is it legit? i.e. according Microsoft's EULA distributing the files individually is not allowed.

As I described above, testing for errors after RMDir $MUI_TEMP solves the (timing) problem, so I am able to deliver a working uninstaller using Microsoft's required method.
nsnb is offline   Reply With Quote
Old 29th June 2010, 22:18   #8
CrushBug
Senior Member
 
Join Date: May 2005
Posts: 119
Well, we got the instructions on how to extract the two files from within the redist from an MSDN blog article. We have shipped 2 retail products like this. I cannot see how this could violate a MS EULA. All we are doing is unpacking an archive we are NOT redistributing the actual VC runtime files themselves.
CrushBug is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Tags
$smprograms, execwait, uninstall, windows 7

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump