Automating Excel from a scheduled task when NOT logged into Windows?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Shadowpheonix
Posts: 1259
Joined: 16 Apr 2015, 09:41

Automating Excel from a scheduled task when NOT logged into Windows?

06 Dec 2018, 22:33

I seem to have encountered bit of a problem accomplishing a task my boss has asked of me...
The task is to automatically merge Excel documents that are dropped into a specific folder, and place the resulting combined document into a different folder. The folder must be checked for new files every 5 minutes.

I figured that would be simple enough with a bit of Excel automation via ComObject and Windows Task Scheduler to run it every 5 minutes, and I was indeed able to get this all working successfully.

However, my boss has also stated that this has to all be accomplished without leaving anyone logged into the server, and without storing any credentials in the script itself. This is where things are falling apart for me - I can only get my script to work if I am logged into the server and have the "Run only when user is logged on" option enabled on the task in Task Scheduler. If I switch to the "Run whether user is logged on or not" option on the task, the script stops working.

By adding FileAppend, %A_LineNumber%, ScriptLog.txt as every other line, I was able to determine that the script is stopping when it hits the oExcel := ComObjCreate("Excel.Application") line if the "Run whether user is logged on or not" option is used.

I assume it is something to do with the way Windows Task Scheduler is handling the user permissions, but I am not 100% certain of this and have no idea what to do about it either way.


Any assistance would be greatly appreciated.



Here's the AHK code I am currently using...
Spoiler
toralf
Posts: 868
Joined: 27 Apr 2014, 21:08
Location: Germany

Re: Automating Excel from a scheduled task when NOT logged into Windows?

14 Dec 2018, 10:29

I‘m not an expert in this field.
To my knowledge it is not possible with AHK.
AFAIK you would have to write a service that could be run on the server with a scheduler. Don‘t think this is possible with AHK.
ciao
toralf
User avatar
gwarble
Posts: 524
Joined: 30 Sep 2013, 15:01

Re: Automating Excel from a scheduled task when NOT logged into Windows?

14 Dec 2018, 19:04

The problem is likely with excel and not ahk:

https://stackoverflow.com/questions/423 ... r-logs-off

For what its worth, a service is possible with ahk, but not needed with task scheduler tasks
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: ReyAHK, Rohwedder and 254 guests