Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing by executing a process in a Windows Service

I have a Windows Service that needs to start a process to send a file to the printer (I found that solution there https://stackoverflow.com/a/4875755/1228738) . I do this using the Process.Start(). My problem is that nothing happens.

The service is actually installed on my developer machine (win7, x64). I tried installing it as LOCAL SYSTEM, NETWORK SERVICE, LOCAL SERVICE with the same result every time.

I tried those way of starting my process :

Process p = new  Process();
p.StartInfo.FileName = "C:\\Program Files (x86)\\Foxit Software\\Foxit Reader\\Foxit Reader.exe";
p.StartInfo.Arguments = "-p myFile.pdf";
p.Start();

and

Process.Start("C:\\Program Files (x86)\\Foxit Software\\Foxit Reader\\Foxit Reader.exe", "-p myFile.pdf");

and also

ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "C:\\Program Files (x86)\\Foxit Software\\Foxit Reader\\Foxit Reader.exe";
startInfo.Arguments = "-p myFile.pdf";

Process.Start(startInfo);

When I execute the same code in a winform application, everything works fine, the file is sent to the printer. But in the Windows Service, nothing happens.

I saw that post https://stackoverflow.com/a/6271309/1228738, which explains why I would not see the UI, that's fine I don't have any UI anyway. But as said in the comment section, a process with no user input should be OK. The process that I start don't need any user input.

The only thing I can think of right now, is that because of session isolation (https://stackoverflow.com/a/5063750/1228738), the service can't find any installed printers... Can that be the case ? If so, any suggestion how to work around that ? And if not, any idea of what's wrong ?

Thanks!

EDIT #1

I tried running the service with my user account, and it's working, so I guess my fears are confirmed... the users LOCAL SYSTEM and NETWORK SERVICE have no installed printers.

So I'll refine my question a little bit. Is there a way for those account to access printers installed on the computer ?

EDIT #2

We finally decided that a user will be created for running that service and in that user accounts we'll install the printer on which to print.

I guess this question can be closed now. Thank you all for your help.

like image 286
Fid Avatar asked Feb 28 '12 20:02

Fid


1 Answers

I had this issue too, this trick solved it

Go to services ---> Double click the required service ---> proceed to logon tab

Supply the Log-in credentials from which printer was installed.

Run your service, then check the printer queue.

Reason: Local system account does not have those printer installed !

See screen shot below.enter image description here

like image 146
Edwin O. Avatar answered Oct 06 '22 02:10

Edwin O.