首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >VB不显示PDF Reader

VB不显示PDF Reader
EN

Stack Overflow用户
提问于 2015-02-03 18:23:23
回答 2查看 720关注 0票数 1

我使用以下代码打开PDF文件:

代码语言:javascript
复制
Public Sub Execute_Doc(afilename As String, Optional style As ProcessWindowStyle = ProcessWindowStyle.Minimized)
        Dim myProcess As New Process

        Const ERROR_FILE_NOT_FOUND As Integer = 2
        Const ERROR_ACCESS_DENIED As Integer = 5


        Try
            myProcess.StartInfo.FileName = afilename
            myProcess.StartInfo.WindowStyle = style
            myProcess.Start()
        Catch e As System.ComponentModel.Win32Exception
            If e.NativeErrorCode = ERROR_FILE_NOT_FOUND Then
                Console.WriteLine(e.Message + ". Check the path.")
                MsgBox("File<" + afilename + "> not found!")
            Else
                If e.NativeErrorCode = ERROR_ACCESS_DENIED Then
                    Console.WriteLine(e.Message + ". You do not have permission to print this file.")
                    MsgBox("File <" + afilename + "> couldn't be opened!")
                End If
            End If
            MsgBox(e.ToString())
        Catch ex As Exception
            MsgBox(e.ToString())
        Finally
            myProcess.Kill()
            myProcess.Dispose()
        End Try
    End Sub

我调用了Execute_Doc("C:\ProgrammName\Test.pdf",ProcessWindowStyle.Normal),但是Adobe Reader不会出现。我可以在任务管理器中看到它。

如果我通过点击桌面上的默认图标,在没有任何文件的情况下启动Adobe Reader,它就能正常工作。它还可以与Windows 8.1中集成的PDF Reader配合使用。我无法在我的Windows 7/ VS 2013计算机上调试此isse。这个问题只存在于一个地方!客户端计算机。

有什么建议如何解决这个问题吗?

EN

回答 2

Stack Overflow用户

发布于 2015-02-03 18:53:46

代码语言:javascript
复制
Public Sub Execute_Doc(afilename As String, Optional style As ProcessWindowStyle = ProcessWindowStyle.Minimized)
    Dim myProcess As New Process

    Const ERROR_FILE_NOT_FOUND As Integer = 2
    Const ERROR_ACCESS_DENIED As Integer = 5


    Try
        myProcess.StartInfo.FileName = "AcroRd32.exe " & afilename
        myProcess.StartInfo.WindowStyle = style
        myProcess.Start()
    Catch e As System.ComponentModel.Win32Exception
        If e.NativeErrorCode = ERROR_FILE_NOT_FOUND Then
            Console.WriteLine(e.Message + ". Check the path.")
            MsgBox("File<" + afilename + "> not found!")
        Else
            If e.NativeErrorCode = ERROR_ACCESS_DENIED Then
                Console.WriteLine(e.Message + ". You do not have permission to print this file.")
                MsgBox("File <" + afilename + "> couldn't be opened!")
            End If
        End If
        MsgBox(e.ToString())
    Catch ex As Exception
        MsgBox(e.ToString())
    Finally
        myProcess.Kill()
        myProcess.Dispose()
    End Try
End Sub
票数 1
EN

Stack Overflow用户

发布于 2015-02-03 22:26:14

只需使用Shell执行它是由Win API提供的,因此您不必担心安装了什么程序来处理扩展。Windows会为您完成这项工作。

代码语言:javascript
复制
Private Function ShellExecute(ByVal File As String) As Boolean
   Dim myProcess As New Process
   myProcess.StartInfo.FileName = File
   myProcess.StartInfo.UseShellExecute = True
   myProcess.StartInfo.RedirectStandardOutput = False
   myProcess.Start()
   myProcess.Dispose()
End Function
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28296521

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档