How to avoid wrong print size when .bat / .py files executed to print via Windows task scheduler?

Question:

I’m currently working on a task to send information from a handheld via a Windows Server to a printer.
For this I use a batch-file that is starting a python-file.

title "RestApi"
call D:ProgramDataMiniconda3Scriptsactivate.bat
start "Rest" D:ProgramDataMiniconda3python.exe D:pathRest.py

in the py-file there is a part included to open a picture in paint to print it onto envelope #9 paper.

cmd = f'mspaint /pt ' + r'card.png ' + '"' + printer + '"'
        print(cmd)
        p = subprocess.Popen(cmd, shell=True)

And here there is the problem. If I manually start the batch-file when logged in on the server as admin, everything is fine and the card is printed as expected.

However, if I automate the task via Windows task scheduler there is another print size given. Means, not all of the information is visible anymore.

Task is running with "SYSTEM" account
Start parameters for the script

Does anybody has an idea why this failure happens and how to solve it?
I would really appreciate your help!

Thanks and best regards
Chris

Already tried to directly execute the py-file by opening python.exe in task scheduler combined with argument (py-file) and started in the path where the py-file is stored.
Seems, it doesn’t work 🙁

Asked By: ChrisKu

||

Answers:

I havn’t done any admin on windows for a long time, but in the past years there was an option in the task scheduler for running the task as another user (a desktop user)

my guess here is that you indeed run the scheduled task under the system account (a special builtin account) that does not have all the environment and access necessary for your use case (which is inded a desktop task). So ticking this option and select your account (or a service account created for the script) can help.

Answered By: webofmars