Search code examples
excelvbabackground-processpidwindows-task-scheduler

Show hidden Excel instance that is started by windows scheduler


I have some windows tasks that are scheduled every day for a specific time. Those tasks have the action to open an excel workbook, which includes some vba (create reports and send via mail) that is running on workbook_open and closes automatically after all code is done. Because of some internal stuff, I have to run those tasks with the option "Run whether user is logged on or not". So the excel instance will run in background. If I log on with the same user, the excel is not seen. Only as a process in details. I know, this is the sense of the task option "Run whether user is logged on or not". If the excel tool is working fine this is no problem. But sometimes it's running on an error which makes the tool to never complete. Because the excel is hidden I can not have a look at the debugger to identify the problem, due to the windows task option...

Do anyone know if it is possible to open that hidden excel workbook which is running on error by logging on with the same user that is set for the scheduled windows task?

I tried it with some code that opens hidden instances of excel, but that wasn't working. I also searched for scripts that opens hidden excel workbooks by the PID. But I found nothing...

PS: Sorry for my English, but I hope its understandable.

UPDATE 2020-07-08: To clarify - Because of windows update processes that will reboot windows each week, I have to set the jobs with the option described above, to be sure they are getting executed. If I got it right, there is no way to make those excel files visible if started in the background by the windows scheduler, even not if I logon with the same user after the job was startet by the scheduler... SOLUTION: I will switch to a windows server installation, that I am able to control the update process by myself. So I can be logged on permanently and am able to run the jobs without the "background"-option of the scheduler.


Solution

  • The short answer to your question is : No

    Unfortunately, since Windows Vista, when a task is started by the Task Scheduler with the option Run whether user is logged on or not enabled, the process will start as a background process and there is apparently no way to make it interact with the user*. The MSDN article on the topic states :

    If this radio button is selected, tasks will not run interactively.

    And far as I understand it, that seems to indicate that Microsoft imposes restrictions on tasks that run whether the user is logged in or not such that they can't be interactive (which includes being visible to the user).

    See also this question on the topic.

    However...

    In your question, you said "Because of some internal stuff, I have to run those tasks with the option Run whether user is logged on or not". I'm just wondering if that is really necessary.

    There is a relatively common misconception (or at least that's what I thought initially) that if you select Run only when the user is logged on, the task won't run if you are on the Lock Screen. That is not true!

    As long as the user has already logged in at least once since the computer was booted up, the task will run. It's a bit misleading since you'd normally consider not being logged in if you have to enter your password, but since the user account/desktop was already loaded, the task scheduler can operate as if the user is logged in.


    * Side note:

    Some Excel processes labeled as background processes can be made visible when they were created with VBA (from a visible Excel app). You would put the following lines in a .vbs file an run the script.
    Set oXLApp = GetObject(,"Excel.Application")
    oXLApp.Visible = True
    

    But I tried it and it doesn't seem to work for an Excel window created from the Task Scheduler with Run whether user is logged on or not enabled. It seems like the Task Scheduler, in this case, imposes some additional restrictions on the Excel window.