How to determine the Windows default browser (at the top of the start menu) - windows

How can I determine the Windows default browser (at the top of the start menu)?
I am using VB6 but can probably adapt other code no problem.
There are similar questions on Stack Overflow, but they seem to provide incorrect answers.
For instance the key HKEY_LOCAL_MACHINE\Software\Clients\StartMenuInternet\ lists both Internet Explorer and Firefox on my PC.
And getting the .html association fails for me as well, as HTML files are associated with IE but Firefox is my default browser.
Note that I don't want to actually open the browser, just get it's name.

When you click on a .html file, the browser that opens it is the one that has registered the .html extension.
When you open a http:// link (e.g. by typing it into the "Start->Run" box), the browser that opens is the one that has registered the HTTP protocol (although it's usually the same browser in both cases).
Whatever is displayed in Start Menu is not related to this.
HKEY_CURRENT_USER\Software\Classes\http\shell\open\command\(Default) is the current user's handler for the HTTP protocol (which means "default browser"; NOTE: this is NOT the same thing as the .html default handler!).
However, it is possible to have a different browser at the top of Start Menu without changing the default. FYI, the browser executable name in Start menu is stored in HKEY_CURRENT_USER\Software\Clients\StartMenuInternet\(Default).

Tested in Windows 7 x64:
This is a two step process. The user's default browser is in key:
HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.html\UserChoice\Progid
Common browser Key Name:
IE: IE.AssocFile.HTM
FireFox: FirefoxHTML
Chrome: ChromeHTML
Opera: Opera.HTML
Replace <KEY NAME> below with one of the values above to find the executable:
HKCR\<KEY NAME>\shell\open\command
Autohotkey script to display the default browser path and executable:
MsgBox % "Default browser: " Browser()
Browser()
{
; Find the Registry key name for the default browser
RegRead, BrowserKeyName, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.html\UserChoice, Progid
; Find the executable command associated with the above Registry key
RegRead, BrowserFullCommand, HKEY_CLASSES_ROOT, %BrowserKeyName%\shell\open\command
; The above RegRead will return the path and executable name of the brower contained within qoutes and optional parameters
; We only want the text contained inside the first set of quotes which is the path and executable
; Find the ending quote position (we know the beginning quote is in position 0 so start searching at position 1)
StringGetPos, pos, BrowserFullCommand, ",,1
; Decrement by one for the StringMid to work correctly
pos := --pos
; Extract and return the path and executable of the browser
StringMid, BrowserPathandEXE, BrowserFullCommand, 2, %pos%
Return BrowserPathandEXE
}

Default browsers are usually set on a per user basis. Have you tried HKEY_CURRENT_USER instead? Shows up on mine under there correctly.

reg QUERY HKEY_CLASSES_ROOT\htmlfile\shell\open\command /ve
you'll get something like
HKEY_CLASSES_ROOT\htmlfile\shell\open\command
(Default) REG_SZ "C:\Program Files\Internet Explorer\iexplore.exe" %1

Related

Icon (DefaultIcon) is displayed differently

I'm struggling with the icon of my application's document files.
First, I'm registering the file extension:
HKEY_CLASSES_ROOT\.Ext\(default) = AppName
Then I give it a shell open command and a icon:
HKEY_CLASSES_ROOT\[AppName]\shell\open\command\(default)="path\app.exe"
HKEY_CLASSES_ROOT\[AppName]\DefaultIcon\(default)="path\app.exe",0
The icon is displayed in Explorer, but not the original one, instead it displays it on a white sheet:
The left one is the associated file, the right one is the executable.
How do I set the registry entries to get the original icon displayed?
I don't know if DefaultIcon supports quotes on the path, other than that the registration looks OK.
After writing these entries you should call SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, 0, 0) so other applications can refresh themselves.
The document icon is generated by the shell (GIL_SIMULATEDOC) when it cannot find a valid DefaultIcon entry but it knows which executable it is going to use. This can happen if you use "Open With" to open your file-type when it has no registration.
Try calling SHChangeNotify and then reboot. If that does not fix it then you should search the registry for your file extension and remove it from Explorers HKCU FileExts keys and any "auto" entries for your type in HKCR. Clearing the shell iconcache might also help.

Change start -> run -> chrome to include switches

I've looked around the internet for a way to use Windows's Windows+R shortcut to run chrome (or any app) with with default command-line switches.
My wife and I share a Windows User, but in Chrome, we have separate users so we don't have to share settings, bookmarks, etc.
Chrome has a switch --profile-directory="[someDir]" that will allow you to set the user when it's run. I'm the only one who uses the Windows+R shortcut, so I'd like to set the default setting, when I type "chrome", to run a chrome instance with my user, regardless of the last chrome window opened (which is how it decides which user to run).
It looks like the right place to make this change is in the registry:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe
If I edit the (Default) key to include --profile-directory="Default", Windows can't find the path, presumably because it puts quotes around the whole thing when I press enter on the Run dialog box.
Using something akin to SQL Injection and adding strategically placed quotes doesn't work either--my guess is that it escapes them.
MSDN hints that you might be able to add command-line parameters as subkeys to the ...\App Paths\chrome.exe key, but I tried adding --profile-directory = "Default", --profile-directory= = "Default", and --profile-directory="Default" = (empty string), none of which worked.
Anyone know how to do this, or are perhaps better at Google than I am?
As a last resort, I can replace the (Default) reg key to point to a batch file that runs chrome.exe with the switch, but I would really rather not.
It seems that you need to use the internal Chrome profile name.
I'm running ChromePortable, so the first thing I had to do was change the user-data-dir
chrome://version helps confirm the profile in use....
At first I thought a full path was required. Actually, it's just the internal name that's referenced...
Here's an example of my revised Chrome shortcut
L:\OS\MyApps\GoogleChromePortable\App\Chrome-bin\chrome.exe --user-data-dir=L:\OS\MyApps\GoogleChromePortable\Data\profile --profile-directory="Profile 1"
(as always, re command args, any spaces should be surrounded by quotes)

FTYPE/ASSOC priority and adding to OpenWithList from the command line

(Not sure if this belongs on superusers, but it seems there is a cmd.exe tag here, so here goes...)
As background, I'm working on a Firefox add-on (This question does not require knowledge of Firefox, btw, as Firefox add-ons can call the command line.) The add-on aims to build different kinds of shortcuts to cmd.exe (especially for the sake of my project https://github.com/brettz9/webappfind which allows files to be opened directly from the desktop into web apps).
Anyways, I'd like to give users the option to associate these shortcuts:
As the default handler for specific file extensions or file types.
To show up within the Open With list of applications (even if the user opts not to make the apps as default handlers)
As far as the default handling, I have found the ftype and assoc (and associate) commands, but I have read that user selections will override their behavior. Is there some way to ensure that I can get priority from the command line in associating file extensions to types and specific executables (until the user changes it again), or if it is not possible, then at least through C++ or the like?
As far as the Open With list:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\<file extension>\OpenWithList
...in my testing (with an exe), this command:
reg add HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.svg\OpenWithList /v d /d D:\wamp\www\webappfind\cplusplus\WebAppFinder-view-mode-Firefox.exe
...did cause the exe file to show up in:
reg query HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.svg\OpenWithList
...but it did not show up when I subsequently right-clicked a file with the ".svg" extension.
I would really appreciate any help with these two points.
REGEDIT4
[HKEY_CURRENT_USER\Software\Classes\Applications\MYFOO.exe\shell\open\command]
#="\"C:\\MYFOO.exe\" \"%1\""
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.myfoo]
"Application"="MYFOO.EXE"
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.myfoo\OpenWithList]
"a"="MYFOO.EXE"
"MRUList"="a"
So I got to an investigation what makes those file associations. It appears that you have to create a mapping from the bare EXE name to the full path as shown in the first two long-ish lines. Then you must only use the EXE name in the .extension branch. Setting the .extension's Application value will give you your default app instantly. Remember, only use APP.EXE, its full path must be defined as above. This was your main error. The "%1" part allows you to customize the parameters of your program so that it doesn't have to be just the opened document in quotes, as shown here. The backslashes are just escape characters for Regedit, you may discard them as you see fit.
The OpenWithList is tricky in the sense that there are letters for entries and just a blind write may overwrite some of the user's favorite apps. One approach would be to call your item "z" to lower the probability of overwriting. The right way would be enumerating the key and giving your app the first free letter. The MRUList is not essential, although it should have each used letter once and yours bumped to the start.
Note about user friendliness: Explorer will cache these values until next reboot. Make sure you update the registry and place exe first and create your file later. Although the caching only fully influences the display of the file and when it is run, the registry is read again and it will execute as you want.
TIP: If you decide to use Regedit instead of reg, the /s parameter skips the confirmation message and applies the values right away. Make sure you use double backslashes in the full path as shown. When preparing your temporary .reg file, make sure you append two CRLF's to the end or a glitch may cause your last line of code to be ignored. This sample starts with REGEDIT4 which signifies an ANSI file. If you need support for Unicode in your app path, you'll have to start the file with Windows Registry Editor Version 5.00 and store it in UTF16. This is already a superior solution to calling reg because there's no way you could get CMD.EXE to process special UTF stuff through the command line without mangling.

how to let ruby call default browser to open localfile

In this question, I find that using system('start http://www.google.com') is OK. If the file is in local disk, though, using system('start file:///c:/temp/a.html') doesn't work. How do I have Ruby get the default browser to open a local file?
What do you get when you double click a .html file in Windows Explorer? If it isn't the browser then that is your problem. The 'start' keyword pushes the path through the ShellExecute function, for http:// URLs is knows to open that in a browser, if it is a file it depends on the extension of the file, if your system has .html pointing to notepad for example (because in the past you have set it to notepad) it is always going to open it in that program unless you go and specifically change it.
From a generic work around point of view there is not much you can do, if you can access the Windows registry under Ruby then you can query the HKEY_CLASSES_ROOT\http\shell\open\command default value which contains a command line for the current browser bound to the HTTP protocol, you could use that to construct a full path (replace the %1 with the URL string).

firefox open local link to directory with explorer

On a Website for our internal use i show links to local files and folders. the links are like this:
href="file://C:/example/"
href="file://C:/example/test.odt"
The Problem is now that the link to the directory does open in firefox itself with a useless directory listing. Useless because you can just see the files or open them but not copy, insert, delete...
The link to the file work normal and the file is opend by OpenOffice.
By changing the configuration of firefox and setting the following key to false I can open the directory in with explorer.exe but for the file I have to choose the right application.
network.protocol-handler.expose.file
Does someone know a way to get both to work like i want? Means that the Directory is shown by explorer.exe and all files are opened by the right application.
This can be by configuring Firefox or windows, changing the links, or even by writing a small program which opens all the file protocol correctly and will be used as protocol handler for the file protocol in firefox.
Thanks
Raffael
I did the above with small changes in Firefox 14.0.1, which works for me:
Create new boolean value network.protocol-handler.expose.file and set it to false
Create new boolean value network.protocol-handler.external.file and set it to true
Click on a link to a local folder.
In the following prompt, link to the explorer.exe in: C:\Windows\explorer.exe
Files are now open with the default application, folders are open with the Windows Explorer!
I know this is not quite what you want, but you might take a look at the "launchy" addon for firefox:
https://addons.mozilla.org/en-US/firefox/addon/81/
Using this addon you can right click on a file link, go to "launchy" sub-menu, and tell it to open in explorer. This will browse directly to the folder as you want.
I want the same feature you want, however this "works" for now. I have asked the author of launchy to allow it to override the left-click behavior for certain protocols (so it would launch explorer with one click), but I don't have a response yet.
edit: Years later, I will post the solution I started using instead of Launchy:
https://addons.mozilla.org/en-us/firefox/addon/local-filesystem-links/
https://github.com/feinstaub/firefox_addon_local_filesystem_links
This scans for file:// links and makes them clickable. It does inject some HTML which can mess with formatting if you aren't careful, but it does the job.
In about:config You need to add a boolean value with the name network.protocol-handler.expose.file and set it to false and also create a string value with the name capability.policy.default.checkloaduri.enabled and set it to allAccess.
Now you will be able to choose C:\Windows\explorer.exe to open file links.
Tested in FF 19.0.2 in Windows 7.
Try this:
Create new boolean value with the name
network.protocol-handler.expose.file and set it to false
Create new boolean value with the name
network.protocol-handler.external.file and set it to true
Open link to a local directory and on the now appearing box, register the "file"-protocol permanently with the "file"-programm (1st entry).
There should now open the windows explorer.
You can deassociate the type "file" in the Firefox-settings (applications-tab).
After that, a link to a document (i.e. file:///x:\dir\file.doc) worked automatically for me (FF8.0).
Or You can use the Plugin "Local Filesystem Links" (DE version of the page) now.
--
edit:
Link for EN version: https://addons.mozilla.org/en-US/firefox/addon/local-filesystem-links/?src=search

Resources