Using windows10 task scheduler to run python script that uses win32 to run excel file. Whenever user is logged in or not

Question:

So I got a python script that uses win32com to open excel file.

win32com.client.Dispatch("Excel.Application")

This python script is triggered by windows10 task scheduler and works fine when I remove the excel part from it. Even with option "run whenever user is logged in or not". But if the script has to open excel then task scheduler ends the task with 0x1 code which means permissions problem. "Use highest privileges" option is checked. When I toggle the task to run only when user is logged in everything works fine.

After hours of searching web I created a "Desktop" directory in C:WindowsSysWOW64configsystemprofile (I have 64 bit OS) and tried to change Excel settings in the dcomcnfg but there is no "Microsoft Excel Application" in the DCOM config. How can I fix this issue? I need to run excel file everyday without being logged.

Asked By: Mateusz Styrna

||

Answers:

So to make it working I had to change settings of the "Microsoft Excel Application" in the DCOM config but the problem was: there was no "Microsoft Excel Application".

Turns out I have 32 bit Microsoft Excel on a 64 bit Windows 10 so I had to run "mmc -32" (Microsoft Management Console) and run dcomcnfg from there and then change DCOM settings for "Microsoft Excel Application".

Answered By: Mateusz Styrna