3

I have a small VBS script that I want to run once per day.

Set objExcelApp = CreateObject("Excel.Application")
objExcelApp.Visible = True
objExcelApp.DisplayAlerts = False

sFilePathXlsm = "C:\Users\$$$$\Desktop\test.xlsm"
Set iWb = objExcelApp.Workbooks.Open(sFilePathXlsm)

sMacroToRun = "'" & sFilePathXlsm & "'!helloworld"
objExcelApp.Run sMacroToRun

iWb.Save
iWb.Close
objExcelApp.DisplayAlerts = True
objExcelApp.Quit

Inside the Windows Task Scheduler I put this for the Program/Script:

"C:\Windows\System32\cscript.exe"

This for the Add Argument:

"C:\Users\$$$$\Desktop\script.vbs"

When I run this with "Run only when user is logged on" it works fine. But if I select "Run whether user is logged on or not", nothing happens and the script does not run.

This script is going to be put inside a VM, so the user may be logged in or not (don't know). So I need to guarantee that this script will run by itself with and without a user logged in.

2
  • Task Manager does not accommodate this so far as I know. You need Task Scheduler (Admin Tools) instead.
    – anon
    Commented Sep 5, 2022 at 15:33
  • @John thanks for relying. Does this mean to run Task Scheduler as Admin? If so I just tried this and same issue. Commented Sep 5, 2022 at 15:56

1 Answer 1

3

You're calling Excel, which is an interactive application.

When you select "Run whether user is logged on or not", then this can only run as a non-interactive task that doesn't need a desktop.

4
  • Is there any other workaround here? I need a way for this vbscript to run for years so I need a stable/reliable source, not having to worry about user being logged off or something like this. Commented Sep 5, 2022 at 16:00
  • Maybe set up another VM that's always logged in with an admin account that just runs this script for each user in C:\Users.
    – LesFerch
    Commented Sep 5, 2022 at 18:29
  • @LesFerch Can you do that with VM's? Like always have it running? Isn't everything on a server somewhere - what happens if this server goes down taking the VM down with it? Don't really understand the in's and out's of how VM works - I think I could convince someone though to have a 24/7 running VM - if in case that is an option. Commented Sep 5, 2022 at 19:52
  • It's a lot of overhead for one script, but it's doable. You would need to set up something to auto start the VM. If there were some way to process the files with a non interactive program, that would be best. Maybe someone else will chime in with a better idea. Keep checking back.
    – LesFerch
    Commented Sep 5, 2022 at 20:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .