Sub Main()
' 既定のブラウザとメーラのパスを取得する
Dim browserPath As String = GetDefaultBrowserExePath()
Dim mailerPath As String = GetDefaultMailerExePath()
' ブラウザとメーラを立ち上げる
Process.Start(browserPath)
Process.Start(mailerPath)
End Sub
Private Function GetDefaultBrowserExePath() As String
Return _GetDefaultExePath("http\shell\open\command")
End Function
Private Function GetDefaultMailerExePath() As String
Return _GetDefaultExePath("mailto\shell\open\command")
End Function
Private Function _GetDefaultExePath(ByVal keyPath As String) As String
Dim path As String = ""
' レジストリ・キーを開く
' 「HKEY_CLASSES_ROOT\xxxxx\shell\open\command」
Dim rKey As RegistryKey = _
Registry.ClassesRoot.OpenSubKey(keyPath)
If Not rKey Is Nothing Then
' レジストリの値を取得する
Dim command As String = _
CType(rKey.GetValue(String.Empty), String)
If command = Nothing Then
Return path
End If
' 前後の余白を削る
command = command.Trim()
If command.Length = 0 Then
Return path
End If
' 「"」で始まる長いパス形式かどうかで処理を分ける
If command.Chars(0) = """"c Then
' 「"〜"」間の文字列を抽出
Dim endIndex As Integer = command.IndexOf(""""c, 1)
If endIndex <> -1 Then
' 抽出開始を「1」ずらす分、長さも「1」引く
path = command.Substring(1, endIndex - 1)
End If
Else
' 「(先頭)〜(スペース)」間の文字列を抽出
Dim endIndex As Integer = command.IndexOf(" "c)
If endIndex <> -1 Then
path = command.Substring(0, endIndex)
Else
path = command
End If
End If
End If