Finding path of application using VB.NET
In a VB application I am building, I need to launch Outlook. Obviously, on every computer the path to Outlook will not be the same. Thus, I need to know how to find the path of Outlook on the user's co开发者_如何学Gomputer before I Shell("path"). How would I do this?
Usually Outlook is installed into the environment path, so you could just use:
Process.Start("Outlook.exe")
First, the user might have multiple versions of Outlook installed.
You could try this registry path:
HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths\OUTLOOK.EXE\Path
...Works for me!
If you're going to send an email, etc, by the way, you could run the commandline, mailto:address@here.com
- look at the mailto:
protocol. It will launch any email client.
If you simply want to send mail via outlook (or any default email client), you can always just shell mailto:name@host.com
, which will create a new mail message with the email in the subject line. You can also append other variables using an HTML email shell.
Otherwise...
You can check if Microsoft Office is installed, and grab the path via the registry. You can then navigate to the Outlook directory e.g.
Sub CheckOfficeXPInstalled()
InstallRoot = System.PrivateProfileString("", _
"HKEY_LOCAL_MACHINE\Software\Microsoft\Office\10.0\Common\InstallRoot", _
"Path")
If InstallRoot <> "" Then
MsgBox "An Office XP Family Product is installed at " & InstallRoot
End If
End Sub
See How to programatically determine if Microsoft Office is installed
You don't lauch Outlook by finding its exe.
You launch it by creating it.
Dim o As Object = CreateObject("Outlook.Application")
o.Visible = True
(Requires Option Strict Off
)
It depends on the version of Office you're using but, for Office 2010 on 64-bit Windows the Microsoft Office install root folder is held in the Path
value under the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Office\14.0\Outlook\InstallRoot
. For 32-bit Windows remove the Wow6432Node
. OUTLOOK.EXE
lives in the folder specified by this registry value.
I think that one of the .net environment variables will point to the default program files directory. But if a user installs anywhere this you may simply have to use the FileSystemObject object and run round the file system looking for outlook.exe.
精彩评论