title: How to succesfully run a batch file in an SQL Agent job?
body: <p>Dear Stackoverflow users,</p>
  
  <p>I have a SQL Agent Job which generates a specific report in PDF-file and then copies the PDF to a network directory and then deletes the PDF file in the source directory.</p>
  
  <p>The SQL Jobs consists of 2 steps:
  1. Generate the report
  2. Copy the report to the network location.</p>
  
  <p>For step 2 I made a bat-file which handles the copying and removal of the pdf file.</p>
  
  <p>The bat-file is as follows:</p>
  
  <pre><code>set source_dir=C:\Reports\Energie\Uur
  set dest_dir=\\KWS2-WEB-SERVER\Share\Reports\Uur
  
  C:\Windows\System32\Robocopy.exe %source_dir% %dest_dir% /MOV /Z
  </code></pre>
  
  <p><em><strong>However, when I run my the Job, it hangs on the second step. The status just stays on "Executing".</em></strong></p>
  
  <p>This is the line which I stated in the step (location of the bat-file to execute):</p>
  
  <pre><code>cmd.exe /c "C:\Reports\rapport_uur_copy.bat"
  </code></pre>
  
  <p>My job-settings are as follows:</p>
  
  <p><strong>Step 1</strong></p>
  
  <p>Type: Operating system (CmdExec)
  On Success: Go to the next step</p>
  
  <p>On Failure: Quit the job reporting failure</p>
  
  <p><strong>Step 2</strong></p>
  
  <p>Type: Operating system (CmdExec)</p>
  
  <p>On Success: Quit the job reporting success</p>
  
  <p>On Failure: Quit the job reporting failure</p>
  
  <p><strong>Some facts:</strong></p>
  
  <ul>
  <li>I have read/write permissions on the network directory</li>
  <li>I run the steps as the Administrator-account (the logged in user, default)</li>
  <li>Step 1 succeeds  </li>
  <li>I run Windows Server 2008 R2 Standard</li>
  <li>I have SQL Server 2008 R2</li>
  <li>When I run the script from the cmd manually, it works (under Administrator account).</li>
  </ul>
  
  <p>Thanks in advance!</p>