Batch File Hangs. How Can I Effectively End It?  

Page 2 of 2 FirstFirst 12

  1. Posts : 1,161
    W10-Pro 22H2
       #11

    Further to the above, I have now found that (whatever I thought I tested yesterday), when run as a scheduled task, Outlook does not get shut down - I was using the simplest script, 'closeoutlook.vbs' - so I tried 'killoutlook' and that worked. I don't need to be graceful (I think)...
      My Computer


  2. Posts : 3,249
    Win10
       #12

    chasfh:

    I too couldn't close Outlook when using the same cscript as you in task scheduler. So, instead of
    cscript.exe "C:\Users\[name]\Documents\Outlook Files\Close Outlook Scheduled Task Files\CloseOutlookFailsafe.vbs"

    I tried
    wscript.exe "C:\Users\[name]\Documents\Outlook Files\Close Outlook Scheduled Task Files\CloseOutlookFailsafe.vbs"

    and upon testing, I got a messagebox to the effect that
    "ActiveX component can't create object Set objOutlook = CreateObject("Outlook.Application")

    which suggested (at least to me with my limited knowledge of VBS) that although manually running the VBS script would work, somehow, it needs more debugging when automating it through task scheduler.

    update:
    Sorry, task scheduler with CloseOutlookFailsafe.vbs did run successfully, after I changed

    General Tab:
    Run whether user is logged on or not
    Run with highest previleges

    Action Tab:
    Program/script Box: %windir%\system32\wscript.exe
    Add Arguments Box: "full path of the .VBS script in double quotes "
    { If you prefer using batch file, then in
    Program/Script Box: cmd.exe
    Add Arguments Box: enter /C followed "full path of the .BAT in double quotes " eg /C "C:\scripts\olook.bat"
    -that should stop the cmd task running after it is done

    The first part of "CloseOutlookFailsafe.vbs" according to the site you linked, is supposed to be "closing Outlook similar to closing Outlook via File-> Close or by pressing the Close button ( X ) in the top-right corner of the Outlook window", and if it doesn't close after 30 seconds (30000 ms), it is forced to quit using the second part of the .vbs. During my testing, it always closed 30 seconds after the task trigger regardless of whether Outlook was busy or not.
    ps: this was with o/l 2010


    Sorry for another update, this works too:

    Task Schedule General Tab only the following is selected :
    Run only when user is logged on
    Configure for: Win 10

    Task Schedule Action Tab :
    Action: Start a Program
    Program/Script: cmd.exe
    Add arguments (optional) Box: /C followed by full path of your .BAT file all enclosed in double quotes (as in your post)
    eg /C "C:\scripts\olook.bat"
    This seems to work as intended; ie if Outlook is not busy it will close immediately otherwise it waits for 30000ms (as shown in the .VBS) before being closed forcefully.
    A command box will remain open for the 30000ms only. The task scheduler may need F5 to be pressed if you want to make sure the task isn't still running.
    Last edited by das10; 17 Jan 2020 at 05:13.
      My Computers


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd
All times are GMT -5. The time now is 09:19.
Find Us




Windows 10 Forums