3

I have the below code in ASP.NET C# and it work fine in local system + production machine when i tested in debug mode. but it doesn't work when i uploading to IIS.

ProcessStartInfo startInfo = new ProcessStartInfo();
                startInfo.FileName = Server.MapPath(filePath);
                startInfo.Verb = "print";
                startInfo.Arguments = "Printer Name";
                Process proc = new Process();
                proc.StartInfo = startInfo;
                proc.Start();

                proc.WaitForExit(5000);
                if (proc.HasExited == false)
                {
                    proc.Kill();
                }

Things i tried.

  1. Control panel > Admin Services > Services > IIS Admin Service > Log on Tab > check to interact with desktop. Reset IIS Admin and IIS.
  2. Printer Properties > Security > Grand ASPNET, NETWORK SERVICE, EVERYONE to full access.
  3. Tried to set another printer as Default Printer. Reinstall / Add Printer.

I tried all the above with no success. finally i tried below in my machine.config.

  1. WINNT>Microsoft.NET>Framework>v2.52something>Config> machine.config

I replaced this

processModel autoConfig="true"

with this

processModel userName="SYSTEM" password="AutoGenerate"

and i am getting this message

"Before you can perform print-related tasks you need to install a printer"

i am using acrobat 7 and i can print the test page from printer itself and from acrobat software.

Kiquenet
  • 14,494
  • 35
  • 148
  • 243
kaung htet naing
  • 101
  • 1
  • 1
  • 7

2 Answers2

0

The issue may be that IIS runs under a different user that has less permissions than a typical User. See System.Diagnostics.Process.Start not work from an IIS

I fixed it on my server by changing the ProcessModel Identity to a user that has permissions. Probably a workaround and bad practice, but it worked. {Application Pool} -> Advanced Settings -> Identity -> Custom Account (Also toggle Load User Profile to true)

Community
  • 1
  • 1
sha1
  • 545
  • 3
  • 14
0

you can use Verb if acrobat is installed on you machine. and pass printer name as arguments

var fileName = @"c:\pdf\file.pdf";
            var startInfo = new ProcessStartInfo(fileName);
            string verbToUse = "PrintTo";
            startInfo.Verb = verbToUse;
            startInfo.Arguments = "PrinterName";
            Process p = Process.Start(startInfo);
Shoaib Shaikh
  • 4,565
  • 1
  • 27
  • 35
  • you will have to install acrobat reader on the production machine.. Windows have to detect that .pdf extension has acrobat reader assocaited with it.. – Shoaib Shaikh Jan 20 '12 at 09:56
  • yes i have already installed it in production machine. actually i have already managed to print in production machine using old code that i posted in my question. help – kaung htet naing Jan 21 '12 at 00:14
  • try using the "print" verb instead of "PrintTo" – Shoaib Shaikh Jan 21 '12 at 09:01
  • alright... try creating a sample console app from the example given in this article http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.verb%28v=vs.90%29.aspx – Shoaib Shaikh Jan 26 '12 at 05:18
  • Hi thanks Shoaib, but as i stated above, it is working fine in debug mode. so even if i create a sample console app, it will also work in debug mode. i think it's something related with security issue in IIS. help! – kaung htet naing Jan 26 '12 at 06:41
  • can you check EventViewer for you server where site is hosted.. there must be some detail about what cause not to print – Shoaib Shaikh Jan 26 '12 at 07:22
  • thanks Shoaib, all the event viewer logs are normal and nothing seems related to my printer problem. it's local printer and i tried both print and printto with no success. – kaung htet naing Jan 27 '12 at 00:24