How to start an Adobe Reader or Acrobat from VB.NET?

11,715

Use a try catch for it.
And you do not always need to provide a path ."Some programs you can start with just the name"

Adobe acrobat = acrobat
Acrobat reader = AcroRd32
Visual studio = devenv
And so on

Now to the code :)

First check if the file exists with If My.Computer.FileSystem.FileExists(FilePath) Then
If file exists you do the try."If not MsgBox("File not found.")"

So first try to open Adobe Acrobat "Process.Start("acrobat", FilePath)"
If that dos not work do another try in the catch.
So now try to open acrobat reader."Process.Start("AcroRd32", FilePath)"
Again if this dos not work use the catch do do another try.
But now just use "Process.Start(FilePath)".
So in the last catch you tell the user to instal acrobat reader. :)

Dim FilePath As String = "C:\Test.pdf"
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    If My.Computer.FileSystem.FileExists(FilePath) Then
        Try
            Process.Start("acrobat", FilePath)
        Catch ex As Exception
            Try
                Process.Start("AcroRd32", FilePath)
            Catch ex2 As Exception
                Try
                    Process.Start(FilePath)
                Catch ex3 As Exception
                    MsgBox("Instal Acrobat Reader")
                End Try
            End Try
        End Try
    Else
        MsgBox("File not found.")
    End If

End Sub
Share:
11,715
Ira D
Author by

Ira D

Updated on June 04, 2022

Comments

  • Ira D
    Ira D almost 2 years

    From Windows Explorer, double-clicking a PDF opens the document in Adobe Reader. Perfect!

    But PROCESS.START(pdfdocumentpath) in my Winforms application opens the PDF in IE. Is there a setting somewhere that will allow PROCESS.START (or other VB.NET code) to open the document in the same way as Windows Explorer?

    Some of my users have 32-bit machines, some have 64-bit machines. Some have Adobe Reader, some have Adobe Acrobat. Some may be a version or more behind, some will be current. Some will have the products in their standard locations, some may have installed them elsewhere.

    What I want to do is open the document in Adobe Reader if they have it and Adobe Acrobat if they have that.

    How can I accomplish this?