Re: How to change the default browser in Visual Studio programmatically
I’d really like to thank Scott Hanselman for digging into the nitty gritty details of how to change the Visual Studio Default Browser.
But… let me cite one of the comments:
Should adding browser options to Visual Studio be
<sarcasm>
this easy</sarcasm>
?
I hope we all agree on: Go fix this!
As I have not found my way to powershell (yet) and I want to have VS Integration (as Scott finalizes his post) too: Here comes the macro version…
Sub SetInternetExplorerAsDefaultBrowser()
Dim FilePath As String = _
Path.Combine( _
Environment.GetFolderPath( _
Environment.SpecialFolder.UserProfile), _
"AppData\Local\Microsoft\VisualStudio\10.0\browsers.xml")
Dim xml As String = "<?xml version=""1.0""?>" & vbCrLf & _
"<BrowserInfo>" & _
"<Browser>" & _
"<Name>Internet Explorer</Name>" & _
"<Path>""C:\Program Files (x86)\Internet Explorer\IEXPLORE.EXE""</Path>" & _
"<Resolution>3</Resolution>" & _
"<IsDefault>True</IsDefault>" & _
"<DDE><Service>IExplore</Service>" & _
"<TopicOpenURL>WWW_OpenURL</TopicOpenURL>" & _
"<ItemOpenURL>""%s"",,0xffffffff,3,,,,</ItemOpenURL>" & _
"<TopicActivate>WWW_Activate</TopicActivate>" & _
"<ItemActivate>0xffffffff,0</ItemActivate>" & _
"</DDE>" & _
"</Browser>" & _
"</BrowserInfo>"
If (File.Exists(FilePath)) Then
File.Delete(FilePath)
End If
Using sw As New StreamWriter(FilePath)
sw.Write(xml)
End Using
Dim ConfigFile As New FileInfo(FilePath)
Using key As RegistryKey = _
Registry.CurrentUser.OpenSubKey( _
"Software\" & _
"Microsoft\" & _
"VisualStudio\" & _
"10.0\" & _
"WebBrowser\" & _
"ConfigTimestamp", _
True)
key.SetValue( _
"LastConfigurationTimestamp", _
DateTime.Now.ToUniversalTime().ToFileTime(), _
RegistryValueKind.QWord)
key.SetValue( _
"CacheFileDateLastMod", _
ConfigFile.LastWriteTimeUtc.ToFileTime(), _
RegistryValueKind.QWord)
key.SetValue( _
"CacheFileSizeBytes", _
ConfigFile.Length, _
RegistryValueKind.DWord)
End Using
End Sub