I am running Windows7 64 bit and Outlook 2010
I have a batch file that produces a different result if I double click on it vs if I run it from Task Scheduler
I have at .bat file that has the following command:
The command is supposed to close any running Outlook Processes.
The contents of CloseOutlook.vbs:
Function IsProcessRunning( strServer, strProcess )
Dim Process, strObject
IsProcessRunning = False
strObject = "winmgmts://" & strServer
For Each Process in GetObject( strObject ).InstancesOf( "win32_process" )
If UCase( Process.name ) = UCase( strProcess ) Then
IsProcessRunning = True
On Error Resume Next
Dim strComputer, strProcess
strProcess = "outlook.exe"
strComputer = "."
If( IsProcessRunning( strComputer, strProcess ) = True ) Then
Set Outlook = GetObject(, "Outlook.Application")
If Err = 0 Then
WScript.Echo "Process " & strProcess & " is NOT running on computer " & strComputer
If I double click on my batchfile it works perfect. However if I schedule it in Task Scheduler it doesn't close outlook. If no Outlook is running it it does give me the message, "Process outlook.exe is NOT running on computer " But if Outlook is running it apparently finds it and does nothing.
In Task Scheduler I have "Run with highest privileges" set.
I have tried running it "only when user is logged on" and "whether user is logged on or not"
The batch file has other commands and it runs to completion without error, but Outlook remains open.