title: Windows script - run silent but wait for completion / return right code
body: <p><strong>Here's my situation:</strong></p>
  
  <ul>
  <li>I have a BAT file that takes a long time to run (1minute to 70 minutes)</li>
  <li>I schedule it with Windows scheduler to run every 10 minutes</li>
  <li>If it schedules again while it is still running, nothing happens (this is good)</li>
  </ul>
  
  <p>My problem is that I need my BAT to run silently, and it doesn't.  So, I want to launch it with a Windows script like the following:</p>
  
  <pre><code>Set WshShell = CreateObject("WScript.Shell") 
  WshShell.Run chr(34) &amp; "C:\Batch Files\syncfiles.bat" &amp; Chr(34), 0
  Set WshShell = Nothing
  </code></pre>
  
  <p>Unfortunately, when I schedule this script, it does the job but returns <strong>instantly</strong>, making Windows scheduler think the task is finished when in reality the BAT is just running off by itself somewhere.</p>
  
  <p>Because of this, Windows will reschedule the job again 10 minutes later and make multiple run.</p>
  
  <p><strong>What I need:</strong></p>
  
  <p>Is there a way to tell the Windows script file to wait for the target of the .Run command to complete before progressing/exiting?  Basically, I want it to act like I launched another thread and then called join on it, so it does the same thing the BAT would have, but without displaying the console window.</p>
  
  <p><strong>Other Solutions</strong></p>
  
  <p>Tell me any other way to get this BAT to execute silently (powershell commands, whatever) and I'll accept it as a solution as well.  Just don't tell me to write a full on C++/C# appliation around it, that's overkill :)</p>
  
  <hr>
  
  <p><strong>Running:</strong> Windows Server 2008 R2</p>