title: How to Quit or Close (not Kill) Word document (process)?
body: <p>In our company we are using Windows application to generate Word (2010) documents. Sometimes the document is not properly closed, so another application (yes, they still call it development:) kill word process which is running more than 1 minute.</p>
  
  <p>These killed processes are stored in MS Word's "Document Recovery". These Document recovery is not possible to turn off in Word 2010 (Options/"Save Autorecover info.." does'n solve the problem). When these "Document Recovery" is full of documents (tens or hundreds), the application stops to generate documents and we need to manually clear the front.</p>
  
  <p>I was able to write this script to identify and kill the processes which are running more than 10 seconds, but is there a way how to close it properly (without killing it)?</p>
  
  <p>I found this tutorial to create and quit word document with powershell, but how to connect specific word process with these MS Office method to close document?</p>
  
  <p><a href="http://www.petri.co.il/generate-microsoft-word-document-powershell.htm" rel="nofollow noreferrer">Powershell and Word tutorial</a></p>
  
  <pre><code>$timer = 10
  $date = Get-Date
  
  if (Get-Process winword*) {
      Get-Process winword | foreach { 
          if ((($date - $_.StartTime).Seconds) -gt $timer) {
              $procID = $_.id
              Write-Host -ForegroundColor Magenta "Process $procID is running longer than $timer seconds."
              Write-Host -ForegroundColor Green "Killing process $procID.."
              Stop-Process $procID
          }
      }
  }
  </code></pre>