我使用以下代码打开PDF文件:
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。这个问题只存在于一个地方!客户端计算机。
有什么建议如何解决这个问题吗?
发布于 2015-02-03 18:53:46
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发布于 2015-02-03 22:26:14
只需使用Shell执行它是由Win API提供的,因此您不必担心安装了什么程序来处理扩展。Windows会为您完成这项工作。
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 Functionhttps://stackoverflow.com/questions/28296521
复制相似问题