none
Problem opening PDF file from Outlook RRS feed

  • Question

  • Hello, 

       I have an app in VB.NET where I let any user login using their Active Dir a/c and the app lets user access their mail using the Outlook. I use WinApi. I launch Outlook using Process class. Here's my code:

        Private Sub LaunchOutlook(ByVal UserName As String, ByVal SecurePassword As SecureString, ByVal Domain As String)
            Dim Impersonator As New ClsAuthenticator
            Try
    
                Log.Add("LaunchOutlook: UserName " & UserName & " SecurePass Length: " & SecurePassword.Length & " Domain: " & Domain)
                Dim OutlookProcess() As Process = System.Diagnostics.Process.GetProcessesByName("outlook")
                If OutlookProcess.Count = 0 Then
                    Dim PSI As New ProcessStartInfo
                    PSI.UserName = UserName
                    PSI.Password = SecurePassword
                    PSI.Domain = Domain
                    PSI.FileName = GetOutlookPath() & My.Settings.OutlookAppExe
                    PSI.Arguments = My.Settings.OutlookAppArgs
                    PSI.LoadUserProfile = True
                    PSI.UseShellExecute = False
    
                    'Impersonator.Impersonator(Domain, UserName, My.Application.CurrentUser.UserPass)
                    OutlookProc.StartInfo = PSI
                    OutlookProc.Start()
                End If
            Catch ex As Exception
                Log.Add("LaunchOutlook Failed: " & ex.Message)
                Throw New Exception("Unable to launch Outlook: " & ex.Message)
            Finally
                'Impersonator.Undo()
                Impersonator = Nothing
            End Try
        End Sub

        The problem that I am facing is - in Win 10 when user logs in and opens Outlook user can open any file attachment type except PDF. Some how, I am not able to open the PDF file. PDF file can be Preview, Copy but not opened.

        I tried Impersonate, but it doesn't work. If I added the Impersonate line before creating the Process, it would open the mailbox of the system logged user and not the application logged user. And If I put Impersonate line where it is right now, it gives "Access Denied" error. Any idea how do can I make PDF files open as normal using the default app like Edge, any PDF reader. Any help is highly appreciated.

    Thanks

    Tom

    • Edited by Tom_Joseph2 Tuesday, February 5, 2019 2:38 PM Where Impersonate fails.
    Tuesday, February 5, 2019 1:47 PM

All replies

  • Hello,

    To start with please present your current code else we can only guess at what has been tried and failed.

    Use the code button for code you post.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Tuesday, February 5, 2019 2:20 PM
    Moderator
  • Hello, 

       I have an app in VB.NET where I let any user login using their Active Dir a/c and the app lets user access their mail using the Outlook. I use WinApi. I launch Outlook using Process class. Here's the code:

        Private Sub LaunchOutlook(ByVal UserName As String, ByVal SecurePassword As SecureString, ByVal Domain As String)
            Dim Impersonator As New ClsAuthenticator
            Try
    
                Log.Add("LaunchOutlook: UserName " & UserName & " SecurePass Length: " & SecurePassword.Length & " Domain: " & Domain)
                Dim OutlookProcess() As Process = System.Diagnostics.Process.GetProcessesByName("outlook")
                If OutlookProcess.Count = 0 Then
                    Dim PSI As New ProcessStartInfo
                    PSI.UserName = UserName
                    PSI.Password = SecurePassword
                    PSI.Domain = Domain
                    PSI.FileName = GetOutlookPath() & My.Settings.OutlookAppExe
                    PSI.Arguments = My.Settings.OutlookAppArgs
                    PSI.LoadUserProfile = True
                    PSI.UseShellExecute = False
    
                    'Impersonator.Impersonator(Domain, UserName, My.Application.CurrentUser.UserPass)
                    OutlookProc.StartInfo = PSI
                    OutlookProc.Start()
                End If
            Catch ex As Exception
                Log.Add("LaunchOutlook Failed: " & ex.Message)
                Throw New Exception("Unable to launch Outlook: " & ex.Message)
            Finally
                'Impersonator.Undo()
                Impersonator = Nothing
            End Try
        End Sub

        The problem that I am facing is - in Win 10 when user logs in and opens Outlook user can open any file attachment type except PDF. Some how, I am not able to open the PDF file. PDF file can be Preview, Copy but not opened.

        I tried Impersonate, but it doesn't work - throws error "Access denied". Any idea how do can I make PDF files open as normal using the default app like Edge, any PDF reader. Any help is highly appreciated.

    Thanks

    Tom

     

      

      

    Tuesday, February 5, 2019 2:32 PM
  • Hi Tom_Joseph2,

    >>The problem that I am facing is - in Win 10 when user logs in and opens Outlook user can open any file attachment type except PDF. Some how, I am not able to open the PDF file. PDF file can be Preview, Copy but not opened.

    Does it throw any exception when open the pdf file. does it work by using outlook instead of Progress. 

    In addition, you could check the steps mentioned by the following link.

    https://www.intowindows.com/fix-edge-not-opening-pdf-files-in-windows-10/

    Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. 
    Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. 
    There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet. 

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, February 6, 2019 5:57 AM
    Moderator
  • Thanks for your response, Zhanglong Wu

    • I did try all options and fixed MS Edge (which was not setup) and made Edge as default app to open pdf files.
    • It does show me warning "You should only preview files from a trustworthy source)."
    • I try to Quick Print - error "Windows cannot find 'C:\Users\Temp\AppData\Local\Microsoft\Windows\NetCache\ContentOutlook\file.pdf'. Make sure you typed the name correctly and try again.
    • "Save As" by default saves to "Temp" User folder & I don't have access to the folder thru explorer also. So, can't open from there. I can definitely save in Public user a/c and access from there.

       I tried accessing the same user a/c from another system (I personally use this system & Edge is also fine), and on Process.Start() it shows error - “Invalid dir name” (File name found while Debug - C:\Program Files\Microsoft Office\Office16\Outlook.exe). 

      

          I see different results on different systems. I believe some sort of system settings differ; can't make out what are they or any required permissions or so. Can you please guide what might be the problem and how do I make it work.

    Thanks 

    Tom

    <o:p></o:p>

    Wednesday, February 6, 2019 4:26 PM
  • Hi Tom_Joseph2,

    Here is a similar issue, which resolved by repaired settings via "fix compatibility problems" window.

    https://answers.microsoft.com/en-us/windows/forum/windows_10-files/cannot-open-pdf-files-in-win-10/4b5712bf-3445-4328-898d-7e92ac4e4e9b

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, February 7, 2019 3:40 AM
    Moderator
  • In reference to your statement:

    I tried accessing the same user a/c from another system (I personally use this system & Edge is also fine), and on Process.Start() it shows error - “Invalid dir name” (File name found while Debug - C:\Program Files\Microsoft Office\Office16\Outlook.exe). 

    C:\Program Files\Microsoft Office\Office16\Outlook.exe refers to the 64 bit version of outlook it possible that some computers are running the 32 bit version.

    Not being able to see the code associated with GetOutlookPath() & My.Settings.OutlookAppExe

    It's not a good idea to store hard coded paths to applications in My.Settings it's better to get the path from the registry that was set when Outlook was installed on that computer.

    I think I can solve your this portion of the problem, Change the line of code:

    PSI.FileName = GetOutlookPath() & My.Settings.OutlookAppExe

    to

    PSI.FileName = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\OUTLOOK.EXE", Nothing, Nothing)


    Be sure that the following line's My.Settings.OutlookAppArgs is putting Quotes around the profile name just in case the profile name has embedded spaces

    PSI.Arguments = My.Settings.OutlookAppArgs

    Make a test line by replacing the above with:

    PSI.Arguments = "/profile " & """" & "Profile Name" & """"


    Next lets look at your issue:

    • I try to Quick Print - error "Windows cannot find 'C:\Users\Temp\AppData\Local\Microsoft\Windows\NetCache\ContentOutlook\file.pdf'. Make sure you typed the name correctly and try again.
    • "Save As" by default saves to "Temp" User folder & I don't have access to the folder thru explorer also. So, can't open from there. I can definitely save in Public user a/c and access from there.

    First of all the folder "'C:\Users\Temp\AppData\Local\Microsoft\Windows\NetCache\ContentOutlook" doesn't look right at all.  What version of Windows are you running and what version of Outlook are you running on the computer that generated this error? As far as I can find out from Windows 8.1 and above the temp folder should be along the lines of

    C:\Users\<yourusername>\AppData\Local\Microsoft\Windows\INetCache\Content.Outlook/5RU2W0PH/

    You can see what it is set to on any computer by running regedit.exe (Be careful  using regedit.exe if you don't know what you are doing).

    Run regedit.exe while logged into windows under username that the problem exists on and find the registry key: 

    Computer\HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Outlook\Security\OutlookSecureTempFolder

    In my case on Windows 10 Outlook 16 it is:

    C:\Users\larry\AppData\Local\Microsoft\Windows\INetCache\Content.Outlook\5RU2W0PH\

    This may lead you in the direction to solve the problem.

    OR HERE IS SOME CODE THAT WORKS WITH NO IMPERSONATION:

    Pass LaunchOutlook this the name of your profile
    To Create a Profile for each user on a particular computer see:
    How to Create Profiles in Outlook

    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            'Pass LaunchOutlook this the name of your profile
            'To Create a Profile for each user on a particular computer see:
            ' https://help.redtailtechnology.com/hc/en-us/articles/203966750-What-is-an-Outlook-Profile-
            LaunchOutlook("Larry Gmail")
            'LaunchOutlook() 'This launces the default profile named "outlook"
        End Sub
    
        Private Sub LaunchOutlook(Optional pstrProfileName As String = "outlook")
            Try
                Dim strProfileName As String = pstrProfileName
                Dim OutlookProcess() As Process = System.Diagnostics.Process.GetProcessesByName("outlook")
                If OutlookProcess.Count > 0 Then
                    For Each objProcess As Process In OutlookProcess
                        objProcess.Kill()
                    Next
                End If
                Dim OutlookProc As New Process ' Create a fresh single instance for this user profile
                Dim PSI As New ProcessStartInfo
                PSI.FileName = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\OUTLOOK.EXE", Nothing, Nothing)
                PSI.Arguments = "/profile " & """" & strProfileName & """"
                PSI.LoadUserProfile = True
                PSI.UseShellExecute = False
                OutlookProc.StartInfo = PSI
                OutlookProc.Start()
            Catch ex As Exception
                'Log.Add("LaunchOutlook Failed: " & ex.Message)
                'Throw New Exception("Unable to launch Outlook: " & ex.Message)
            Finally
            End Try
        End Sub
    End Class




    Wednesday, March 20, 2019 1:56 PM