Sunday, March 6, 2011

After you Ramdisk Chrome: Default the Browser

I set out on a fun adventure to get Google Chrome as well as my Temp directories to run their business off a Ramdisk.

Click here to review a guide on doing this yourself.

My only qualm was, after setting this up, external hyperlinks (I.E.: Help - About, click on a web link in the about window) ran without my command line switches I used for Chrome. I had to sort of jury-rig a workaround, to prevent the system from opening a blank Google Chrome profile each time I hit something in a separate program.

Before detailing how I resolved setting the default browser in Windows, I'm going to go over my personal preferences as far as command line switches so you know what to edit to your own liking.

This switch sets my chrome user data directory on my Ramdisk (Drive R: in my case):

--user-data-dir="R:\Chrome\Userdata"

This switch sets my chrome cache directory so it's sitting in it's own spot on the Ramdisk:

--disk-cache-dir="R:\Chrome\Cache"

This switch gives me 256 Megabytes of max cache (more than enough, really):

--disk-cache-size=268435456

Other switches:

--process-per-tab - This is my personal preference, I like each tab to have it's own process by Tab, not by Site. This way, in the event of a site meltdown, I only need to force close One Process to kill that specific tab, instead of burning dozens of other associated tabs down with it.

--disable-logging - Forces chrome logging to be disabled. Logging is enabled by default in debug builds, and I only tend to use debug builds. Disabling this in debug builds enhances performance a nudge, at the expense of backtracking issues.

--restore-last-session - Indicates the last session should be restored on startup. This overrides the preferences value and is primarily intended for testing. You probably don't need this, but I use it anyway.

For a list of all of Google Chrome's switches, click here.

Please note, I personally am using Vista 64-bit for this guide, so keep in mind that locations / etc. may be different depending on your flavor of Windows. For Linux/Mac, I might make a separate guide sometime in the near future, but if you can understand the process used here, you may be able to assemble your own Mac/Linux flavor of this fix up.

I discovered how the registry value for ChromeHTML works, and I will elaborate how you can use it to quickly make your command line switches a part of opening anything on your OS.

First and foremost - you'll want to pop into Windows Explorer, right-click an .htm file (make a blank one if you have to) and click Open With > Choose Default Program, set Google Chrome as the default. Do the same thing with an .html file.

Fair warning, if you modify the registry, bla bla bla, you can implode the universe, etc, don't come crying to me if you create a living nightmare.

This was done on Vista 64-bit, you may have to change stuff depending on your operating system.

Please note, "MyUser" is your specific user profile on Windows. If you click the Start button, your user name is normally in the upper right corner, under your user avatar picture. Change "MyUser" in the guide below, to Your user name.

Edit below to your preferences, and save as whatever.reg:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\ChromeHTML\shell\open\command]
@="\"C:\\Users\\MyUser\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe\" --user-data-dir=\"R:\\Chrome\\Userdata\" --disk-cache-dir=\"R:\\Chrome\\Cache\" --disk-cache-size=268435456 --process-per-tab --disable-logging --restore-last-session -- \"%1\""


In the above, you should change C:\\Users\\MyUser to reflect your Actual user name, like C:\\Users\\Robert for example.

My command switches are obviously different than your preference, so Change Them to your liking. In the case of my cache location, my Ramdisk drive letter happens to be R: - so change R:\\Chrome\\Cache\ to whatever your actual new Ramdisk drive letter is.

Then just double click the .reg file you made...and pray eternal damnation doesn't force you to use a better operating system, like Linux.

Alternatively, you could just edit the registry value manually - in fact, you probably should, because imploding universes is Bad.

Open regedit, and navigate to: HKEY_CLASSES_ROOT\ChromeHTML\shell\open\command

Again, plug in your string the way you'd like it to be, for me, it was just:

"C:\Users\MyUser\AppData\Local\Google\Chrome\Application\chrome.exe" --user-data-dir="R:\Chrome\Userdata" --disk-cache-dir="R:\Chrome\Cache" --disk-cache-size=268435456 --process-per-tab --disable-logging --restore-last-session -- "%1"

Ensure all silly double-quotes are present and accounted for, as it's pretty critical.

You may now feel free to open [Help > About] in your external program, and violently click the manufacturer's website, to demonstrate your new fantastic hack and impress people everywhere.

You may also wish to set the http/https associations, too. The following registry code can do this, just make sure you set MyUser to whatever your username is, etc, or feel free to browse manually through the registry and change the values the same as before:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\http\shell\open\command]
@="\"C:\\Users\\MyUser\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe\" --user-data-dir=\"R:\\Chrome\\Userdata\" --disk-cache-dir=\"R:\\Chrome\\Cache\" --disk-cache-size=268435456 --process-per-tab --disable-logging --restore-last-session -- \"%1\""

[HKEY_CLASSES_ROOT\https\shell\open\command]
@="\"C:\\Users\\MyUser\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe\" --user-data-dir=\"R:\\Chrome\\Userdata\" --disk-cache-dir=\"R:\\Chrome\\Cache\" --disk-cache-size=268435456 --process-per-tab --disable-logging --restore-last-session -- \"%1\""


This should be all you normally need to set things up.



I will now offer an alternative solution. In the event this registry fix doesn't work quite so well for you, or you have to run a series of command line switches that interfere with the registry somehow, I have another work around for you.

To best figure this out, I had to first create a Batch file to use as a base.

I opened my text editor (Notepad) and saved this as C:\Users\MyUser\AppData\Local\Google\Chrome\Application\runchrome.bat and ran it:

@ECHO OFF
ECHO Please don't close me - running Chrome via RamDisk!
C:\Users\MyUser\AppData\Local\Google\Chrome\Application\chrome.exe --user-data-dir="R:\Chrome\Userdata" --disk-cache-dir="R:\Chrome\Cache" --disk-cache-size=268435456 --process-per-tab --disable-logging --restore-last-session


Neat! So now I have a batch file that launches my half dozen command line switches, and I can add as many switches in here as I wish - effectively breaching the limit imposed by Vista's shortcut properties window.

Now to solve the dilemma of an ugly Batch file window sitting in the background...

First we need to run a little script alongside our original batch file, that virtually hides the batch window for us.

Open Notepad and save the following as:

C:\Users\MyUser\AppData\Local\Google\Chrome\Application\invis.vbs

CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, False

This simple script by itself does nothing, however, when passed the aforementioned batch file - it runs that batch file virtually cloaked. Now we just need a batch file to Run these two files for us...

Open this in a text editor, and save as C:\Users\MyUser\AppData\Local\Google\Chrome\Application\invislaunch.bat :

IF "%1" == "" (
wscript.exe "C:\Users\MyUser\AppData\Local\Google\Chrome\Application\invis.vbs" "C:\Users\MyUser\AppData\Local\Google\Chrome\Application\runchrome.bat"
) ELSE (
echo C:\Users\MyUser\AppData\Local\Google\Chrome\Application\chrome.exe --user-data-dir="R:\Chrome\Userdata" --disk-cache-dir="R:\Chrome\Cache" --disk-cache-size=268435456 --process-per-tab --disable-logging %1 > C:\Users\MyUser\AppData\Local\Google\Chrome\Application\runlinky.bat
wscript.exe "C:\Users\MyUser\AppData\Local\Google\Chrome\Application\invis.vbs" "C:\Users\MyUser\AppData\Local\Google\Chrome\Application\runlinky.bat"
)


What This batch file does, is first checks to see if you passed invislaunch.bat an argument (I.E. a web site like google.com) - if the argument is blank, it simply runs our runchrome.bat file cloaked. Otherwise, if it's been passed an argument like http://google.com - it generates a New temporary batch file script to run against the cloaking vbs! The new temporary batch file would be saved as "runlinky.bat" - and then passed to the cloaking vbs.

To test things out, open invislaunch.bat by itself to open Chrome first. Then open a command prompt (Start > Run > cmd) and change to the C:\Users\MyUser\AppData\Local\Google\Chrome\Application\ directory:

CD C:\Users\MyUser\AppData\Local\Google\Chrome\Application\

Then execute the same invislaunch.bat with a web site:

invislaunch.bat http://www.google.com

You should simply see a new Tab open in your existing Chrome window, instead of a New Chrome window appearing with the old/default profile.

"Wait, but how does that prove anything?"

To show further proof, provided you're using the preference to restore your tabs (or using the --restore-last-session command switch), click the wrench on Google Chrome and click Exit. Then, in the same command prompt, run the invislaunch.bat with a web site again:

invislaunch.bat http://www.google.com

Voila! You should see your current profile open with the web site argument opened in a new tab!

Now, for the Operating System part, all you would do is create two blank files with your text editor in your Documents folder:

test.htm

test2.html

Then just right-click each file, choose Open With, Choose Default Program, Browse for C:\Users\MyUser\AppData\Local\Google\Chrome\Application\invislaunch.bat and set it as the default program.

Not as fancy looking in the explorer window, but officially the OS happily accepts these values as the default web browser.

You might also wish to refer to the earlier mentioned registry hacks to ensure http/https association and everything is in line with your new batch file program. Keep in mind, the double-dashes are unnecessary, so your registry entry would actually look something like:

"C:\Users\MyUser\AppData\Local\Google\Chrome\Application\invislaunch.bat" "%1"

I hope this has helped a few folk out there.

Feel free to drop me a friendly comment, or scream mercilessly if you wish - whatever!

5 comments:

  1. I never knew you had this blog my love! You have a faithful follower now!

    ReplyDelete
  2. Thank you so much for taking the time to post this and some solutions. I will try this on Windows 7 and XP ... Thanks again!

    ReplyDelete
  3. You're welcome! Let me know how things pan out, if you run across another issue we'll try to work it out here.

    ReplyDelete
  4. This page just deleted all my post. I have to write it again, dang it. Anyhow, I'm looking to make a fix like this for XP. I would really REALLY appreciate your help in this. I'm afraid to edit the .reg file because I see it has double "\"'s. I'm not sure if those are escape characters or what. Usually I only see them in 1's not in pairs like that. I don't even know if it wil tell me if you respond to this in my email. I don't see a contact page anywhere, hopefully it does email me.

    ReplyDelete
  5. "Follow-up comments will be sent to (my email)" -- I guess I will be hearing from you, good deal.

    ReplyDelete