How to modification the default browser in Visual Studio programmatically with PowerShell and presumably poke yourself within the eye

in utopian-io •  7 months ago

What Will I Learn?

I've detected and seen various complaints concerning however it's arduous to line the default browser that Visual Studio launches once you launch a rectify session for a web site

Requirements

Windows or other system
PowerShell
"CSI: VISUAL STUDIO DEFAULT BROWSER"

Difficulty

  • Basic

Tutorial Contents

ADEQUATE

Folks pay time searching round the Tools|Options dialog in Visual Studio searching for setting. They eventually notice it is not in there in the slightest degree, however instead you have got to right-click on AN ASPX page among an internet Project and click on "Browse With..."

22.png

From this dialog you'll click Set Default, that is completely obvious, right my daimies? Um, no. this does not work for ASP.NET MVC folks that use different read engines and won't even have a .ASPX come in their resolution. Plus, it's slow and worsening. Sa da tay.

33.png

It IS interesting that I can add other browsers, like Google Chrome to this dialog via Add. Note that Google Chrome installs in C:\Users\Scott\appdata\Local\Google\Chrome\Application\chrome.exe which may not be c:\Program Files where you usually go hunting for these things.

"WHAT MY THOUGHT method WAS" - OR - "CSI: VISUAL STUDIO DEFAULT BROWSER"

Where is that this browser info stored? That was my initial question. bear in mind that your pc isn't a recorder. Even smart programmers build this error and that they "flip this switch and hope that lightweight turns on" while not confirming that the switch and therefore the lightweight square measure connected with smart wire and that they skills electricity works.

I will guess all day, or I will open up ProcMon and simply see for myself. Seriously, learn the way to use this freaking tool. {you will|you'll|you'll be able to} flip lightweight switches all day otherwise you can simply open up the wall and see the wires. If you recognize a way to use method Monitor aptly, individuals of each sexes can directly realize you additional enticing. It's true. i buy all types of free Tacos and Chips once people look am i able to run ProcMon like Keanu Reeves will look unhappy.

I discharged ProcMon up set it to solely show the devenv.exe method, and that i took an opportunity and set 'contains browser' for the trail. If this did not work i might open the flood gates and begin separation a little. I might even have aforesaid 'highlight' things with the word browser if I liked .

44.png

I launch VS, open the Browse With dialog and sweet forward mollassy. inspect all that good things.

55.png

fonts too small, let me zoom in.

66.png

Looks like we're reading values out of the written record at HKCU:\Software\Microsoft\VisualStudio\10.0\WebBrowser\ConfigTimestamp and...

77.png

Paste your text here and click on "Next" to observe this text editor in chief do it's factor.

haven't any text to check? haven't any text to check? Click "Select Samples".


<?xml version="1.0"?>
<BrowserInfo>
  <BrowserInfo>
    <Browser>
      <Name>Google Chrome</Name>
      <Path>"C:\Users\Scott\AppData\Local\Google\Chrome\Application\chrome.exe"</Path>
      <Resolution>0</Resolution>
      <IsDefault>False</IsDefault>
    </Browser>
  </BrowserInfo>
</BrowserInfo>

I've seen of us commit to amendment this with varied extensions in Visual Studio and exploitation automation calls at intervals Visual Studio, however to the simplest of my information, this feature has been in here for years and years and there is no thanks to get at it programmatically.

SLIGHTLY amazing

Interestingly furthermore, my initial try at ever-changing the browser programmatically consisted of this brilliance:

C:\Users\Scott\AppData\Local\Microsoft\VisualStudio\10.0>copy "browsers - firefox.xml" browsers.xml /y
        1 file(s) copied.

But, it appears that those register keys ar serious and extremely used for one thing, as a result of whenever I opened Browse With... I found my changes thrown away, in all probability as a result of VS is not looking forward to file for amendment notification, however rather caching the enter memory.

Looks like employment for PowerShell (yes, i do know will try this with batch files, however PowerShell is much batter, so nyah. Learn it.)

First i would like to work out what is going on on during this register. If I ought to that key (by right-clicking the key inside ProcMon and clicking Jump To), then right-click on the key within the register Editor I get:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0\WebBrowser\ConfigTimestamp]
"CacheFilePath"="C:\Users\Scott\AppData\Local\Microsoft\VisualStudio\10.0\browsers.xml"
"CacheFileSizeBytes"=dword:000000e6
"CacheFileDateLastMod"=hex(b):6f,18,a4,ee,17,41,cb,01
"LastConfigurationTimestamp"=hex(b):00,26,aa,86,09,41,cb,01

88.png

Click Dec(imal) and appears like 230 bytes, the dimensions of my browser.xml file. what is the upset those mod dates, though? They a in all probability a Windows file time, if they are not ticks. Ticks square measure seconds since 1970-1-1 and a Windows FileTime is that the variety of 100-nanosecond ticks since 1601-1-1 rounded to the closest unit of time. Why? as a result of 1601 was AN amazing year. I mean, the Battle of Kinsale stopped the blockade in Kinsale, Ireland, and famine killed 0.5 the Estonians. Sheesh, that was a atrocious year! What we have a tendency tore we thinking!?

Anyway, the simplest thanks to convert one thing you're thinking that could be a Date into a Date (and reason variety 0x3b for you to finally learn PowerShell) is that this line in PowerShell.

PS C:\> [DateTime]129268523480000000
Saturday, August 21, 0410 8:19:08 AM

Lemme do this once more against a blue background with a screenshot thus you actually believe Pine Tree State.

99.png

Oh yes, i am on a horse. Cool. Those area unit FileTimes. So, tappity tappity and here's a PowerShell script to examine the present values and output them for testing.


cd C:\Users\Scott\AppData\Local\Microsoft\VisualStudio\10.0

$browsers = xml
$browsers.BrowserInfo.Browser.Name + " " + $browsers.BrowserInfo.Browser.Path

$regkey = "HKCU:\Software\Microsoft\VisualStudio\10.0\WebBrowser\ConfigTimestamp"

"LastConfigTimestamp: " + ([DateTime](get-itemproperty $regkey).LastConfigurationTimestamp).ToLocalTime()
"CacheFileDateLastMod: " + ([DateTime](get-itemproperty $regkey).CacheFileDateLastMod).ToLocalTime()
"CacheFileSizeBytes: " + (get-itemproperty $regkey).CacheFileSizeBytes

I'll go and develop and run this script within the PowerShell ISE (that's S for Scripting) that you simply have already got on your pc. Freaky however Microsoft sneaks stuff like this on your machine. If you have Windows seven, you are already got this.

1010.png

I run Visual Studio and click on Browse|With... a number of times and watch the values modification. appears i want the SET to my GET script, thus why not one thing like this. I've created copies of browsers.xml like browsers-chrome and browsers-firefox. you'll be able to do an equivalent if you wish.

cd C:\Users\Scott\AppData\Local\Microsoft\VisualStudio\10.0 

copy '.\browsers - firefox.xml' .\browsers.xml
$regkey = "HKCU:\Software\Microsoft\VisualStudio\10.0\WebBrowser\ConfigTimestamp"

set-itemproperty $regkey -name LastConfigurationTimestamp -value (&{[DateTime]::Now.ToUniversalTime().ToFileTime()}) -type qword
set-itemproperty $regkey -name CacheFileDateLastMod -value (&{((dir .\browsers.xml).LastWriteTimeUtc).ToFileTime()}) -type qword
set-itemproperty $regkey -name CacheFileSizeBytes -value (&{(dir .\browsers.xml).Length}) -type dword

What i'm doing during this script? i am repeating my browser xml over the most one and i am change the TimeStamp to currently to urge Visual Studio to re-read the file. Visual Studio looks to be checking and triple checking and if the CacheFileDateLastMod and CacheFileSizeBytes do not mirror reality, it'll freak out and simply delete my file fully and make a brand new browsers.xml from scratch. Paranoid.

You can go and fancy these scripts up with command-line parameters all you wish as a result of you are a higher applied scientist than I, however i'm all Save|As, baby. I even have "UpdateDefaultBrowserToChrome.ps1" and, yes, watch for it, "UpdateDefaultBrowserToFireFox.ps1" and that i sleep in the dark simply fine, thanks much.

I will right click on them on my desktop and choose Run with PowerShell if i prefer.

1111.png

But...still....it can be additional impressive. Darn my folks and also the work ethic they instilled in Pine Tree State as alittle kid.

a pair of - very impressive

You can run PowerShell scripts from the regular not-really-DOS command like this if you wish.

C:\Users\Scott\Desktop>powershell .\UpdateDefaultVSBrowserToChrome.ps1

I might even install PowerConsole and run these commands from within Visual Studio 2010 if i prefer and that i need to tear a hole within the area time time. My, is that intellisense within PowerShell within Visual Studio? Double sun power!!!!

1212.png

Still, this does not match my mindless purpose and click on mouse-like progress. i am going to attend Tools | External Tools and add 2. make certain you decide on the proper PowerShell, which can be x86 notwithstanding you are on x64 therefore you properly access the written record. I additionally checked Use Output window and else one line of text at the lowest of every script.

1313.png

Nice, however why not a toolbar?

PROFIT! I MEAN, deeply AWESOME!

Right click on any Toolbar, this customise and add buttons for External Tools (in my case #6 and #7) and...

1414.png

Which gives me this when I click:

1515.png

And shows this in Browse With, showing me it worked:

1616.png

ROLL UP directions

Go to C:\Users\YOURNAME\AppData\Local\Microsoft\VisualStudio\10.0
Make a bunch of browser-whatever xml files for your browsers, or populate your list from Visual Studio, then create copies.
Make yourself some of those (or create one that switches if you are awesome)

cd C:\Users\YOURNAME\AppData\Local\Microsoft\VisualStudio\10.0

copy '.\browsers - CUSTOMBROWSER.xml' .\browsers.xml
$regkey = "HKCU:\Software\Microsoft\VisualStudio\10.0\WebBrowser\ConfigTimestamp"

set-itemproperty $regkey -name LastConfigurationTimestamp -value (&{[DateTime]::Now.ToUniversalTime().ToFileTime()}) -type qword
set-itemproperty $regkey -name CacheFileDateLastMod -value (&{((dir .\browsers.xml).LastWriteTimeUtc).ToFileTime()}) -type qword
set-itemproperty $regkey -name CacheFileSizeBytes -value (&{(dir .\browsers.xml).Length}) -type dword
"Bam, son. Browser changed to CUSTOM BROWSER."

Add some external tools that decision PowerShell along with your new scripts as parameters.
Add toolbar buttons if you are feeling am passionate about it.
Go write a correct Visual Studio 2010 extension that will all this and packages it up in one click, place in on the VS Gallery and impress your friends and family. Crap. currently I ought to do this for my next post, do not I? Shoot. Kzu? provide Maine a decision and teach Maine the way to try this.



Posted on Utopian.io - Rewarding Open Source Contributors

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Your contribution cannot be approved because it does not follow the Utopian Rules, and is considered as plagiarism. Plagiarism is not allowed on Utopian, and posts that engage in plagiarism will be flagged and hidden forever.

Completely plagiarised from here.

You can contact us on Discord.
[utopian-moderator]