开发者

check Acrobat reader installed in pc and display installer

my Manager asked about autoplay cd which has PDF files and check on user pc if adobe acrobat installed on user pc or not if it dosent installed message apear to install this program from cd I had windows application to check if adob reader or acrobat installed in pc or not I did that well 开发者_如何学编程but I want if this program wasnot installed acrobat reader installer apear from cd and user install this program.

 public Form1()
    {
        RegistryKey adobe = Registry.LocalMachine.OpenSubKey("Software").OpenSubKey("Adobe");
        if (adobe != null)
        { 
            RegistryKey acroRead = adobe.OpenSubKey("Acrobat Reader");
            if (acroRead != null)
            { 
                string[] acroReadVersions = acroRead.GetSubKeyNames();
                MessageBox.Show("The following version(s) of Acrobat Reader are installed: ");

                foreach (string versionNumber in acroReadVersions)
                { 
                    MessageBox.Show(versionNumber);
                } 
            } 

        } 
        else
        { 
            MessageBox.Show("The following version(s) of Acrobat Reader arenot installed: ");

        } 


you need to invoke installer process. something like this.

Process myProcess = new Process();
myProcess.StartInfo.FileName = "path to acrobat installer"; 
myProcess.Start();

Better approach would be to add a custom action in your application setup for this.


There are several ways to check for this.

1/Check installed applications (win installer)

Each Windows installer project (MSI) has an updgrade code and a product code. Simply put, the product code defines the version of the installed application and it's dependencies. The updgrade code stays the same over diffirent versions. You can search the product code for acrobat reader and use windows installer dll to check if it is installed. There is some code on codeproject (search for MsiInterop) which will has all the needed dllimports.

2/ Keep it simple.

Why not just check if there is an application associated with files that have a PDF extension??
If there is an associated application (may be something other than Acrobat Reader, e.g. foxit) assume everything is all right. Otherwise, launch a browser pointing to http://get.adobe.com/reader/

This way, your application does not assume responsability over the user's choice of PDF reader.


Accessing the windows installer in C#:

public enum InstallState
{
       NotUsed = -7,
       BadConfig = -6,
       Incomplete = -5,
       SourceAbsent = -4,
       MoreData = -3,
       InvalidArg = -2,
       Unknown = -1,
       Broken = 0,
       Advertised = 1,
       Removed = 1,
       Absent = 2,
       Local = 3,
       Source = 4,
       Default = 5
}   
[System.Runtime.InteropServices.DllImport("msi.dll", CharSet = CharSet.Unicode)]
internal static extern InstallState MsiQueryProductState(string szProduct);

If you know the product codes for Adobe Acrobat you can query its installation status:

bool acrobatInstalled = allAcrobatReaderProductCodes.Any(guid =>
{
     var productCode = "{" + guid.ToString().ToUpper() + "}";
     var msiState = MsiQueryProductState(productCode);
     return msiState == InstallState.Local || msiState == InstallState.Default);
});

Where allAcrobatReaderCodes is an IEnumerable of all the acrobat reader product codes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜