title: VBScript Closing Application Not Working
body: <p>I am currently learning VBScript and I have written this script just to practise and I am having trouble closing more then one application (notepad and calc) within one script. When I run the applications by itself in a seperate script they close. But when I combined everything together in this script they don't close. Am I doing something wrong with WMI Service?</p>
  
  <pre><code>'*** calc.vbs ***
  
  Set WshShell = CreateObject("WScript.Shell")
  
  WshShell.Run "calc"
  
  WScript.Sleep 1500
  
  WshShell.AppActivate "Calculator"
  
  WScript.Sleep 1500
  
  WshShell.SendKeys "5"
  
  WScript.Sleep 1000
  
  WshShell.SendKeys "{+}"
  
  WScript.Sleep 1000
  
  WshShell.SendKeys "10{+}"
  
  WScript.Sleep 1000
  
  WshShell.SendKeys "12"
  
  WScript.Sleep 1000
  
  WshShell.SendKeys "{=}"
  
  WScript.Sleep 5000
  
  strComputer = "."
  
  Set objWMIService = GetObject("winmgmts:" _
  
      &amp; "{impersonationLevel=impersonate}!\\" &amp; strComputer &amp; "\root\cimv2")
  
  Set colProcessList = objWMIService.ExecQuery("SELECT * FROM Win32_Process 
  
  Where Name = 'calc.exe'")
  
  For Each objProcess In colProcessList
  
      objProcess.Terminate
  
  Next
  
  '*** notepad.vbs ***
  
  WScript.Sleep 5000
  
  WshShell.Run "notepad"
  
  WshShell.AppActivate "Untitled - Notepad"
  
  WScript.Sleep 1000
  
  WshShell.SendKeys "This is the first line "
  
  WScript.Sleep 1000
  
  WshShell.SendKeys "~" ' same as {Enter}
  
  WScript.Sleep 1000
  
  WshShell.SendKeys "This is the second line"
  
  WScript.Sleep 1000
  
  WshShell.SendKeys "{Enter}"
  
  WScript.Sleep 1000
  
  WshShell.SendKeys "This is the third line"
  
  WScript.Sleep 5000
  
  Set colProcessListt = objWMIService.ExecQuery("SELECT * FROM Win32_Process 
  
  Where Name = 'notepad.exe'")
  
  For Each objProcesss In colProcessListt
  
      objProcesss.Terminate
  
  Next
  </code></pre>