如何从VB.NET启动Adobe Reader或Acrobat? [英] How to start an Adobe Reader or Acrobat from VB.NET?

查看:504
本文介绍了如何从VB.NET启动Adobe Reader或Acrobat?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows资源管理器中,双击PDF在Adobe Reader中打开文档.完美的!

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

但是Winforms应用程序中的PROCESS.START(pdfdocumentpath)将在IE中打开PDF.

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?

我的某些用户使用32位计算机,有些用户使用64位计算机.有些使用Adobe Reader,有些使用Adobe Acrobat.有些可能是版本或更高版本,有些将是最新的.有些产品将在其标准位置放置,有些可能已将它们安装在其他位置.

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.

我想做的是,如果有的话,请在Adobe Reader中打开文档;如果有的话,请在Adobe Acrobat中打开.

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

我该怎么做?

推荐答案

为此使用try catch.
而且您不必总是提供路径.某些程序可以仅以名称开头"

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"

Adob​​e acrobat = acrobat
Acrobat阅读器= AcroRd32
Visual Studio = Devenv
等等

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

现在输入代码:)

首先使用If My.Computer.FileSystem.FileExists(FilePath)然后检查文件是否存在
如果文件存在,则进行尝试.如果没有,则为MsgBox("找不到文件.)"

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.")"

因此,首先尝试打开Adobe Acrobat"Process.Start(" acrobat,FilePath)"
如果这样做不起作用,请尝试再次尝试.
因此,现在尝试打开acrobat阅读器."Process.Start(" AcroRd32,FilePath)"
再次,如果这样做不起作用,请使用catch进行另一次尝试.
但是现在只需使用"Process.Start(FilePath)".
因此,在最后一个捕获中,您告诉用户安装acrobat Reader. :)

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

这篇关于如何从VB.NET启动Adobe Reader或Acrobat?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆