Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

lpr command not working from my C# program in Win 7

Tags:

c#

winapi

lpr

I have program that sends a file to a printer using 'lpr' command. I have installed Windows SDK 7.1. It is working fine in a 32 bit Windows 7 system but not working in 64 bit Windows 7.

            Process proc = new Process();
            proc.StartInfo.FileName = "lpr";
            proc.StartInfo.WorkingDirectory = GlobalConstants.outBaseDir;
            proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            proc.StartInfo.Arguments = " -S " + GlobalConstants.printerIP + " -P RAW " + filePath;
            proc.Start();

It throws an execption.

like image 815
Sundeep Avatar asked May 10 '12 22:05

Sundeep


People also ask

How use LPR command in Linux?

To print a file with a specific printer, execute the lp command with the '-d' option or lpr command with the '-P' option. Consider the following commands: lp -d <printer name> <file name> lpr -P <printer name> <file name>

Where is LPR EXE?

In the case of the LPR. EXE, the command was located in %WINDIR%\system32 which means that running a command prompt from the Start menu would cause the 64-bit version of CMD. EXE to run and since this is a 64-bit process it can access the %WINDIR%\system32 directory so the LPR.


1 Answers

I finally got the answer to my question.

Step1: I had to enable "LPR Port Monitor". This can be done through "Control Panel/Programs and Features/Turn Windows features on or off". In the dialog expand "Print and Document Services." Check "LPR Port Monitor."

Step2: When you install Windows SDK 7.1. It will copy lpr.exe and related files into "C:\Windows\winsxs\amd64_microsoft-windows-p..ting-lprportmonitor_xxxx...". Copy the files lpr.exe, lprhelp.dll, and lprmonui.dll into the C:\Windows\sysWOW64 folder.

Thats it!!!

Reference: http://www.tomshardware.com/forum/240019-44-error-windows

like image 183
Sundeep Avatar answered Oct 12 '22 10:10

Sundeep