title: VBScript - no access to text file unless Wscript.Sleep, even though the file is already available
body: <p>I'm still not too experienced with VBScript, so I probably made some rookie mistakes I just don't see, yet.
  What I'm basically trying to do is a workaround for getting the clients license information for MS Office 2013 via a vbscript.
  It's dumping the license information from the ospp.vbs file in the Office folder into a txt file.</p>
  
  <p>Here's an abridged part of my script, that shows the problem:</p>
  
  <pre><code>Set objFSO = CreateObject("Scripting.FileSystemObject")
  Set objShell = Wscript.CreateObject("WScript.Shell")
  Dim IsThere
  If objFSO.fileExists("C:\Program Files\Microsoft Office\Office15\OSPP.VBS") Then
              isThere = True
              objShell.Run "cmd /K cscript ""C:\Program Files\Microsoft Office\Office15\OSPP.VBS"" /dstatus &gt; C:\temp\tmpOutput.txt &amp; exit"
      ElseIf objFSO.fileExists("C:\Program Files (x86)\Microsoft Office\Office15\OSPP.VBS") Then
          isThere = True
          objShell.Run "cmd /K cscript ""C:\Program Files (x86)\Microsoft Office\Office15\OSPP.VBS"" /dstatus &gt; C:\temp\tmpOutput.txt &amp; exit"
      End If
      ' wait for ospp.vbs zu finish and create the temporary txt file with license information
      Do While Not objFSO.fileExists("C:\temp\tmpOutput.txt")
          Wscript.Sleep 10
      Loop
      If isThere = True AND objFSO.fileExists("C:\temp\tmpOutput.txt") Then
      'Wscript.Sleep 4000
          Dim listFile
          listFile = objFSO.OpenTextFile("C:\temp\tmpOutput.txt").ReadAll
          Wscript.Echo listFile
      End If
      ' Delete temporary data file
      If objFSO.fileExists("C:\temp\tmpOutput.txt") Then
          objFSO.deleteFile "C:\temp\tmpOutput.txt"
      End If
  </code></pre>
  
  <p>Running it like this throws the error Input past end of file (800A003E) for the line:</p>
  
  <pre><code>listFile = objFSO.OpenTextFile("C:\temp\tmpOutput.txt").ReadAll
  </code></pre>
  
  <p>If I uncomment the <em>Wscript.Sleep 4000</em>, it works fine and shows the expected result.
  Why does it throw the error, even though I put in the Do-Loop to wait for the file to actually exist?</p>