I have found that the following code:
RMDir /r "$INSTDIR\Documents"
File /r "..\BPQ32\Files\Documents"
will generate random i/o failures thus:
Error opening file for writing
C:\Program Files (x86)\BPQ32\Documents\Thumbs.db
Installer stops at
Output folder: c:\Program Files (x86)\BPQ32\Documents.
This i/o error (although it isn't always the same file name) has occurred on several Windows 7 machines and one XP machine. The occurance rate is low, perhaps one in 10 runs of the installer.
To try to isolate this I placed a MessageBox immediately following the RMDir /r and with that I could never reproduce it. I then replaced the MessageBox with a Sleep 1000 and could never reproduce it. Removing the Sleep 1000 results in the error returning.
I suspect that the RMDir /r operation is using proceed i/o (overlapped, Asynchronous) when it should be using wait i/o (Synchronous).
The RMDir /r operation is apparently not yet completed when the write from the File operation is attempted.