0

the issue I'm facing is this:

I'm trying to start AcrobatReader from my C# WebApplication using a Process.

https://msdn.microsoft.com/en-us/library/system.diagnostics.process(v=vs.110).aspx

When I'm running the application in IIS Express(running under my default user account) everything goes right and I can open the file I want on Acrobat Reader.

Instead, when I'm trying to deploy on IIS(running under IIS APPPOOL\xxx) the process can't start AcrobatReader.

I've already tried to assign permissions on AcrobatReader to IIS_IUSRS and also to IIS APPPOOL\xxx but nothing change

Tried also to add IIS APPPOOL\xxx to administrators group but no luck

`      `ProcessStartInfo info = new ProcessStartInfo();
        info.FileName = Constants.ACROBAT_READER_PATH;
        info.Arguments = args;
        info.Verb = "Printto";
        info.CreateNoWindow = true;
        info.WindowStyle = ProcessWindowStyle.Hidden;
        info.UseShellExecute = false;

        info.Domain = Environment.MachineName;
        info.UserName = "AdminUser";
        string password = "AdminPassword";
        System.Security.SecureString securePassword = new System.Security.SecureString();

        foreach (char c in password)
            securePassword.AppendChar(c);

        info.Password = securePassword;

        try
        {

            //The following security adjustments are necessary to give the new 
            //process sufficient permission to run in the service's window station
            //and desktop. This uses classes from the AsproLock library also from 
            //Asprosys.
            IntPtr hWinSta = GetProcessWindowStation();
            WindowStationSecurity ws = new WindowStationSecurity(hWinSta,
              System.Security.AccessControl.AccessControlSections.Access);
            ws.AddAccessRule(new WindowStationAccessRule("AdminUser",
                WindowStationRights.AllAccess, System.Security.AccessControl.AccessControlType.Allow));
            ws.AcceptChanges();

            IntPtr hDesk = GetThreadDesktop(GetCurrentThreadId());
            DesktopSecurity ds = new DesktopSecurity(hDesk,
                System.Security.AccessControl.AccessControlSections.Access);
            ds.AddAccessRule(new DesktopAccessRule("AdminUser",
                DesktopRights.AllAccess, System.Security.AccessControl.AccessControlType.Allow));
            ds.AcceptChanges();

            using (Process process = Process.Start(info))
            {
            }
        }
        catch (Exception ex)
        {
        }

Thank you for your time

Stefano Vuerich
  • 996
  • 1
  • 7
  • 28
  • 1
    The AppPool isn't running an interactive session, so it can't start interactive applications. The service doesn't have a "window station" or desktop to work with... – Ron Beyer Sep 21 '15 at 20:42
  • Why do you want to start acrobat reader on the server? – John Koerner Sep 21 '15 at 20:47
  • I need to print a pdf from a web application... – Stefano Vuerich Sep 21 '15 at 20:48
  • @RonBeyer even if interactive session it is in, the Adobe process will be invisible to logon users sessions due to session isolation. – Lex Li Sep 22 '15 at 02:23
  • @StefanoVuerich you will have to consume printing API directly. Calling processes in a web application is unreliable. Note that IIS Express hosting is in your session and that's why you can do something that never can work under IIS. – Lex Li Sep 22 '15 at 02:25
  • @Lex Li what do you mean by "consume printing API directly" ? I need to print a PDF so I must use AR or any other PDF software https://social.msdn.microsoft.com/Forums/vstudio/en-US/00c2c76c-9e09-47d0-b34d-52c1a956f15f/how-to-print-pdf-file-programatically-using-c-code – Stefano Vuerich Sep 22 '15 at 09:10
  • @StefanoVuerich http://www.strathweb.com/2012/10/remote-printing-with-asp-net-web-api-in-windows-service/ you don't – Lex Li Sep 24 '15 at 15:07
  • @LexLi really interesting article, thanks for your help – Stefano Vuerich Sep 24 '15 at 21:30

0 Answers0