6

I'm having a problem while trying to open a PDF file using Process.Start(). The program runs the process as a background process but no adobe reader window show up. A solution i found was to use chrome.exe, but my client want to open on adobe-reader, as it's the default windows program.

(I have also trying without forcing "AcroRd32.exe" and passing the full path of "AcroRd32.exe". Same problem).

Anyone solved this?

My code:

var p = new Process
{
    StartInfo = new ProcessStartInfo(@"AcroRd32.exe", @"D:\Tests\81803130000326__.pdf")
};
p.Start();

Background Processes:

Background Process image

I also have checked this question: Process.Start(/* path to pdf */) doesn't work with Adobe Reader on Windows 8

Edits

EDIT INFO: Forgot to say i'm running Windows 10 with Adobe Reader DC 2018.009.20044

EDIT 2: Found a "problem" of Adobe Reader DC. It mantains a level of security that doesn't let me run it as administrator (don't ask me why). Check this link for more information: https://forums.adobe.com/thread/1955530

Now I'll try to find a solution to run it without administrator privileges, or ask my client to uncheck the checkbox

Solution

So, I've found a solution for my problem. The Adobe Reader, since version 10.0, has a "Protected Mode" setting. I wrote a code to change that setting in the registry, so the user won't need to do that. Link: https://www.adobe.com/devnet-docs/acrobatetk/tools/AppSec/protectedmode.html

I hope it helps others in the future!

Solution Code:

var registroAdobe = Registry.LocalMachine.OpenSubKey(@"Software\Policies\Adobe\Acrobat Reader\DC\", true);
registroAdobe.SetValue("bProtectedMode", 0);

This works for Acrobat Reader DC. You can run through "Software\Policies\Adobe\" Products and Versions if you need it.

Wesley
  • 61
  • 1
  • 4
  • 1
    Try passing in the full path to AcroRd32.exe. – Botonomous Nov 27 '17 at 13:48
  • I open direct the pdf file, `System.Diagnostics.Process.Start("output.pdf");`, this use the default pdf viewer that you have installed in your computer. – Pablo Tondolo de Vargas Nov 27 '17 at 13:51
  • @Botonomous Like i said, i got the same problem :( – Wesley Nov 27 '17 at 15:38
  • @PabloTondolodeVargas Same thing occours. All these works the same way. The system\program understants and open the process, but doesn't open the adobe reader window – Wesley Nov 27 '17 at 15:41
  • What's your default program to open pdf files? – Pablo Tondolo de Vargas Nov 27 '17 at 15:42
  • @PabloTondolodeVargas Adobe Reader DC 2018.009.20044 (updated that now) – Wesley Nov 27 '17 at 15:44
  • @Wesley, pass the full path to AcroRd32.exe, like this ` StartInfo = new ProcessStartInfo(@"C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe", @"D:\temp\demonstrativo.pdf")` – Pablo Tondolo de Vargas Nov 27 '17 at 15:52
  • Does your program run as a Windows Service, or otherwise on Session 0 (e.g. Windows Task Scheduler)? Then you can't trivially start applications in the session of the current user. See https://stackoverflow.com/questions/4278373/how-to-start-a-process-from-windows-service-into-currently-logged-in-users-sess, https://stackoverflow.com/questions/5627404/how-can-i-have-a-service-run-a-process-under-the-current-users-session – CodeCaster Nov 27 '17 at 15:58
  • Doesn't work, @PabloTondolodeVargas :( thanks! CodeCaster I'm trying using a new console application for that. The code is literally just that. Discovered the problem on adobe forums. The problem is really Adobe Reader DC. Check my new EDIT – Wesley Nov 27 '17 at 16:51
  • Solution Found! thank you guys! – Wesley Nov 27 '17 at 21:16

2 Answers2

2

Actually, I found that this didn't work on my computer, but it led me to look deeper. I found my solution to be:

var regAdobe = Registry.CurrentUser.OpenSubKey(@"Software\Adobe\Acrobat Reader\DC\Privileged", true);
regAdobe.SetValue("bProtectedMode", 0);

Very similar, but ended up having to edit the user setting rather than the local machine's setting.

Cheers!

DrJonez
  • 21
  • 4
0

You can directly use System.Diagnostics.Process.Start("") to open with default pdfreader program on respective client system.

Pravin .Kadam
  • 99
  • 1
  • 7