Score:0

Program started with Task Scheduler could not open my Printer

mo flag

I have a C# program that executes some commands that generates a pdf and print it to a printer. The printer is hosted in a print server, so the way I accessed the printer is through my app config. (\Print Server Name\Printer Name)

<add key="printServerPrinter" value="\\APPS-UATSVR\NPIFBCC54 (HP LaserJet MFP M430)"/>

This program works when I run it on visual studio or even when I release it and run it via its .exe file. It has to run during work hours so I added it to Task Scheduler to start it to check something every minute and print when it found something.

The problem is if the program is started by the Task Scheduler It can't find the printer, it generates a pdf but can't send it to print on the printer since it couldnt find it. This is the error logged on a .txt file.

2023-07-26 06:32:43:751191 Function:Main - Message:The printer named "\\APPS-UATSVR\NPIFBCC54 (HP LaserJet MFP M430)" could not be opened. Error code: 0

If I start it normally there are no problems, as I have said earlier. I searched around the net but couldn't find an answer and i can't seem to debug this problem. I've tried many ways, changed the printer name, changed the port, change the backslash to forward slash but it still wont work.

What seems to be the problem? Thank you very much in advance!

cn flag
What user is the Task Scheduler running the app as, does it have permission to use the printer?
Kraust123 avatar
mo flag
I think so, the task scheduler use the web_admin account to run the task. Still, doesnt work :(
Score:0
vn flag

Unless you have explicitly told it to use a user account, when Task Scheduler launches an app it will launch it in the Local Service security context. As your printer has not been added to that security context, the task can't reach it - and there may be some problem reaching any network resource from that context in any case. Edit your scheduled task to use your user account, it will need your password in order to have access to your network resources.

Kraust123 avatar
mo flag
It still doesnt work. I've changed the user when running to task to web_admin. And It still doesnt changed anything :(
tsc_chazz avatar
vn flag
And does web_admin have that printer installed? Network printer installations are per user.
Kraust123 avatar
mo flag
yes it is installed.
Kraust123 avatar
mo flag
I forgot to mention that the task scheduler is running on different server
tsc_chazz avatar
vn flag
Leading to the obvious question: does the user web_admin on that other server have the printer installed on that server? Not only per-user, network printer installations are also per machine...
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.