我想通过一个Process对象从VB.NET代码打开Outlook。
Dim PSI As New ProcessStartInfo
' ORG -
'PSI.FileName = GetOutlookPath() & My.Settings.OutlookAppExe ' Returns C:\Program Files\Microsoft Office\Office16\Outlook.exe
'PSI.Arguments = My.Settings.OutlookAppArgs
PSI.FileName = IO.Path.Combine(GetOutlookPath(), My.Settings.OutlookAppExe) ' "/e ""C:\Program Files\Microsoft Office\Office16\Outlook.exe"""
'PSI.Arguments = “/importprf \\comp.us\syscol\comp.us\Software\Outlook2010\comp.prf” ' My.Settings.OutlookAppArgs
下面是GetOutlookPath()方法:
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
上面的代码工作在Win 7,而造成一些赢得10系统的问题。我只是抛出目录名称未发现异常。我试图与实际内容的尝试,以及所有上述方式与空间路径工作更换设置变量的值,但没有任何工程。谁能帮我知道如何设置的路径值,使其在所有运OS工作。在过程中传递的参数也给出了一个困难时期。
打开IE浏览器也给出了同样的错误。下面是IE浏览器的代码:
Private Sub LaunchIE(ByVal UserName As String, ByVal SecurePassword As SecureString, ByVal Domain As String, Optional ByVal WebSite As String = "http://iserver1/comp")
Try
Log.Add("LaunchIE: UserName " & UserName & " SecurePass Length: " & SecurePassword.Length & " Domain: " & Domain & " WebSite: " & WebSite)
Dim PSI As New ProcessStartInfo
'PSI.FileName = GetIEPath() & My.Settings.IEAppExe
'PSI.Arguments = WebSite
'' Tried to open notepad - no space in path, yet it throws "The directory name is invalid" exception
PSI.FileName = IO.Path.GetFullPath("C" & IO.Path.VolumeSeparatorChar & "\Windows\notepad.exe") ' Value = C:\Windows\notepad.exe
PSI.UserName = UserName
PSI.Password = SecurePassword
PSI.Domain = Domain
PSI.LoadUserProfile = True
PSI.UseShellExecute = False
IEProc.StartInfo = PSI
IEProc.Start()
Catch ex As Exception
Log.Add("LaunchIE Failed: " & ex.Message)
Throw New Exception("Unable to launch Internet Explorer: " & ex.Message)
End Try
End Sub
能否请你帮我找出我该如何处理这种情况。
谢谢
设置的ProcessStartInfo的“WorkingDirectory”属性,否则你会得到“目录名称是无效的”。