Ok, reporting back to answer my own question.
The problem was directly related to the setting for 'Display PDF in browser' in Preferences > Internet.
With this option checked, the problem goes away. When it is unchecked, it comes back.
Here is how we propose to handle it programmatically:
private string defaultPdfProg()
{ //Returns the default program for opening a .pdf file; On Fail returns empty string.
// (see notes below)
string retval = "";
RegistryKey pdfDefault = Registry.ClassesRoot.OpenSubKey(".pdf").OpenSubKey("OpenWithList");
string[] progs = pdfDefault.GetSubKeyNames();
if (progs.Length > 0)
{
retval = progs[1];
string[] pieces = retval.Split('.'); // Remove .exe
if (pieces.Length > 0)
{
retval = pieces[0];
}
}
return retval;
}
private void browserIntegration(string defaultPdfProgram)
{ //Test if browser integration is enabled for Adobe Acrobat (see notes below)
RegistryKey reader = null;
string[] vers = null;
if (defaultPdfProgram.ToLower() == "acrobat")
{ //Default program is Adobe Acrobat
reader = Registry.LocalMachine.OpenSubKey("Software").OpenSubKey("Adobe").OpenSubKey("Adobe Acrobat");
vers = reader.GetSubKeyNames();
}
else if (defaultPdfProgram.ToLower() == "acrord32")
{ //Default program is Adobe Acrobat Reader
reader = Registry.LocalMachine.OpenSubKey("Software").OpenSubKey("Adobe").OpenSubKey("Acrobat Reader");
vers = reader.GetSubKeyNames();
}
else
{
//TODO: Handle non - adobe .pdf default program
}
if (vers.Length > 0)
{
string versNum = vers[vers.Length - 1].ToString();
reader = reader.OpenSubKey(versNum);
reader = reader.OpenSubKey("AdobeViewer",true);
Boolean keyExists = false;
Double keyValue = -1;
foreach(string adobeViewerValue in reader.GetValueNames())
{
if (adobeViewerValue.Contains("BrowserIntegration"))
{
keyExists = true;
keyValue = Double.Parse(reader.GetValue("BrowserIntegration").ToString());
}
}
if (keyExists == false || keyValue < 1)
{
string message = "This application requires a setting in Adobe to be changed. Would you like to attempt to change this setting automatically?";
DialogResult createKey = MessageBox.Show(message, "Adobe Settings", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
if (createKey.ToString() == "OK")
{
reader.SetValue("BrowserIntegration", 1, RegistryValueKind.DWord);
//test to make sure registry value was set
}
if (createKey.ToString() == "Cancel")
{
//TODO: Provide instructions to manually change setting
}
}
}
}
A few items to note:
Does anyone know if these locations are interchangeable in all versions or if based on specific versions of Acrobat the registry key is in different locations? Does Reader follow the same logic as Acrobat?
- Does Adobe use any other method to determine the 'default Adobe application for opening PDF files' other than the windows file association? I ask because if you have a non-adobe product, such as FoxIt installed as the default file association application, but are using the ActiveX control for Adobe on a machine that has both Reader and Acrobat installed, what logic is used to decide which application the COM object will talk to?