none
Setting Path dir name with spaces for Process RRS feed

  • Question

  • Hello, 

       I am trying to open Outlook from VB.NET code through a Process object. 

                    Dim PSI As New ProcessStartInfo
                     PSI.FileName = IO.Path.Combine(GetOutlookPath(), My.Settings.OutlookAppExe)  ' "/e ""C:\Program Files\Microsoft Office\Office16\Outlook.exe""" ' GetOutlookPath() & My.Settings.OutlookAppExe
                    'PSI.Arguments = “/importprf \\comp.us\syscol\comp.us\Software\Outlook2010\comp.prf” ' My.Settings.OutlookAppArgs
     
        Private Function GetOutlookPath() As String
            Dim Val As String = ""
            If My.Settings.OutlookAppPath = "" Then
                Try
                    Dim Key As RegistryKey = Registry.LocalMachine.OpenSubKey(My.Settings.OutlookRegPath)
                    Val = Key.GetValue("Path")
                    Val = Val.Replace(";", "")
                    If Val.LastIndexOf("\") <> Val.Length - 1 Then
                        Val = Val & "\"
                    End If
                Catch ex As Exception
                    Log.Add("Unable to get registry value for Outlook: " & ex.Message)
                    Throw New Exception("Unable to get registry value for Outlook: " & ex.Message)
                End Try
            Else
                Val = My.Settings.OutlookAppPath
            End If
            Log.Add("GetOutlookPath: " & Val)
            Return Val
        End Function

    I tried replacing the values of Settins variables with actual content to try, but nothing works. Can anyone please help me know how do I set the path values and make it work on all Win OS. This code was working in Win 7, but with Win 10 it's giving a hard time. The arguments passed in Process also gives a hard time.

    Thanks

    Thursday, February 7, 2019 5:13 PM

Answers

  • I added WorkingSirectory od ProcessStartInfo and it works like a charm.

    Dim path As String = GetOutlookPath()
    PSI.WorkingDirectory = IO.Path.GetPathRoot(path)
    PSI.FileName = path & My.Settings.OutlookAppExe

    Hope this helps some one who is stuck like this.

    Thank You

     

    • Marked as answer by Tom_Joseph2 Thursday, February 7, 2019 9:10 PM
    Thursday, February 7, 2019 9:10 PM

All replies

  • Rather than "hard time" be specific.  What errors are you getting?  Compile time or run time?  Etc.
    Thursday, February 7, 2019 8:55 PM
  • I added WorkingSirectory od ProcessStartInfo and it works like a charm.

    Dim path As String = GetOutlookPath()
    PSI.WorkingDirectory = IO.Path.GetPathRoot(path)
    PSI.FileName = path & My.Settings.OutlookAppExe

    Hope this helps some one who is stuck like this.

    Thank You

     

    • Marked as answer by Tom_Joseph2 Thursday, February 7, 2019 9:10 PM
    Thursday, February 7, 2019 9:10 PM