Opening SMB/CIFS shared files using the Mozilla or Opera browser

See the full article below the updates.
For the impatient: download, save in C:\WINDOWS, Start -> Run -> "smburl3b.vbs register" (no quotes). Run it as administrator on Vista or Windows 7 or see alternatives below in the 2009-12-07 update box.

For a similar approach using a separate .reg file and and a one-line .cmd script that calls explorer.exe see (off-site).

Author / copyright: Walter Doekes

2009-12-07 - update

Reports have come in that the script does not work on Windows Vista.

> Script: C:\Windows\smburl3b.vbs
> Line: 168
> Char: 5
> Error: Invalid root in registry key
> Code: 80070005
> Source: WshShell.RegWrite

This is a security issue. You can either run the script as administrator when registering (the 'register' argument), or replace all occurrences of HKEY_LOCAL_MACHINE with HKEY_CURRENT_USER. The latter option only installs the handler for the currently logged on user.

2008-10-11 - update

The script now assumes all url-encoded characters above 0x7f are encoded UTF-8. This should be correct for the majority of modern browsers. Get the updated script (view).

2008-09-07 - update

What has been changed, is really a bugfix. Spaces aren't allowed in URLs. And nowadays the browsers replace the space with a %20 — mostly as a precaution against vulnerabilities like this. In the LAN search engine that I wrote ages ago, I had forgotten to escape the illegal spaces in the generated URLs. Therefore everything worked just fine until this change happened. While really my URLs should have been broken from the beginning.

So, without further ado, here is an updated version (view), called smburl3a.vbs. This one will urldecode all but the reserved characters. If you were generating smb://-URLs, make sure you escape spaces with %20 and percent signs with %25.

My changes did not include the replacing of pluses (+) with spaces. Should I have added that as well? My initial thought was against, because it's easier for both the URL-generating party and the script.

Thanks Gregory Fong for helping me focus on the issue.

2008-08-20 - update

Somehow the script is getting wrong arguments when spaces and percents are concerned. I haven't had time to figure out what happens exactly, but smb://-urls with spaces seem to be broken nowadays (with my IE7 and FireFox When the URL is smb://abc/d e/f%20g the script receives smb://abc/d%20e/f%20g. That should be either smb://abc/d e/f%20g or smb://abc/d%20e/f%2520g to be usable.

2007-04-26 - update

I can do you one better though. This new and improved version needs only wscript.exe which is installed on all Windowzes nowadays. Save it somewhere and run it with "register" as argument. It will update the registry as necessary. This one won't flash a cmd window either, like the old one did.

Get it now: smburl3.vbs (view)

2007-03-07 - update

More people are using the same fix. See Firefox file links for a solution with a C# binary.

2005-12-07 - update

For those too lazy to read and do manual stuff. Two steps. Fetch sh.exe and put it in some directory in your %PATH%. Fetch smbreg2.cmd and run it.

CMD.EXE batch programming sucks. I haven't found a way to reliably escape the ampersand (&). So, we'll try a different approach instead. You should already have sh.exe - you needed it for the old approach. We'll just run a zsh script instead of a CMD.EXE script. Two things need to be changed: the actual script and the registry keys that call the script. First the zsh script;

#!/usr/bin/env zsh
# vim:syn=zsh
# -- zsh script to open smb:// links on windows.
# Walter Doekes (C) 2005 -- License: Public Domain
# Is it an smb:// link?
if [[ "${ARGS[0,4]}" != "smb:" ]] {
	print "Unsupported format; please provide an smb:// URI."
	print "\nHit [ENTER]."
	read x
	exit 1
# Change the URI from smb://server/share/dir/file to \\server\share\dir\file
# Run rundll with the file:// handler.
rundll32.exe url.dll,FileProtocolHandler "$REPLACED"
## Uncomment the lines below for diagnostics
#print "Tried to open:\n${REPLACED:gs/\\/\\\\\\\\/}\n\nHit [ENTER]."
#read x

And the modified registry keys; smburl.reg. (We assume that you placed sh.exe in your %PATH% and in C:\\WINDOWS.)

"URL Protocol"=""
@="sh.exe \"C:\\WINDOWS\\\" %L"

06-09-2004 - update

Arjen Zonneveld has made a script that automates the process of creating the necessary batch files. It also sets the correct path to the used windows files (in the registry file below you had to edit g:\\winnt to the correct path for your Windows install). After downloading sh.exe and sed.exe (and placing them in a directory that is defined in your %PATH%) you can simply run smbreg.cmd. He also pointed out that this works with the Mozilla browser as well. You won't even have to edit any settings in Mozilla.

2004 - original article


The Opera browser by Norwegian Opera Software is a very capable browser. One thing that has bothered me though, is the following: if you try to open file:// links, opera will download them or - in the case of directories - display it's own browse page. When using the search engine on my Local Area Network, I want to be able to open files directly instead of having to download them to my local drive first, so I was stuck using Internet Explorer for all my LAN searching needs. I couldn't find anything on the net that fixes this (setting a custom file protocol handler in Opera doesn't help), so I created a workaround that uses the unused smb:// protocol.


  1. Create an smb:// protocol handler in the Windows registry.
  2. Create a shell script (batch file) that handles this protocol; namely by reformatting the supplied arguments and feeding them to rundll32.exe.
  3. Add the smb:// protocol to the handlers in Opera.
  4. Convince the admin of your LAN search engine to add smb:// links to files and directories. This shouldn't be too hard because linux browsers often understand that protocol (and not file://).


First we add the following to the Windows registry. Make sure you replace C:\\PROGS\\Utils\\smb.cmd with the filename of the batch file you are to create next (name it .bat if you're running Windows 95/98/ME). You can place this into a file called smb.reg and Merge it into the registry by double-clicking on it.


"URL Protocol"=""




@="C:\\PROGS\\Utils\\smb.cmd %L"

Next we'll make a shell script (batch file). It requires two tools which you most likely do not have installed; namely sed.exe and sh.exe, the former to replace text input, and the latter to execute the replaced text (if this can be done with the tools provided by Microsoft, please tell me how). If you don't trust me, you can fetch the files from the UnxUtils package. Place the two binaries in a directory in your %PATH% (normally C:\WINDOWS\ or C:\WINNT\). After fetching the files, create a file called smb.cmd at the location you specified in the registry above, with the following text:

@echo off
rem - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
rem Opens smb:// directory links with explorer.exe
rem for use with Opera which insists using their own file:// handling
rem - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
rem requires: explorer.exe or rundll32.exe, sh.exe, sed.exe
rem Simple option -- doesn't do files.
rem sh -c "explorer.exe `echo %1 | sed -e 's/^smb:/file:/'`"
rem Complex option -- may show escaping issues
rem sh -c "rundll32.exe url.dll,FileProtocolHandler `echo \"%*\" | sed -e s/^smb:// -e s:/:\\\\\\\\\\\\\\\\:g -e s/%%20/\\ /g`"

sh -c "rundll32.exe url.dll,FileProtocolHandler `echo \"%*\" | sed -e s/^smb:// -e s:/:\\\\\\\\\\\\\\\\:g -e s/%%20/\\ /g`"

All the lines preceded by rem are comments. The script takes the supplied argument - which would look like smb://SOMECOMPUTER/sharename/path/to/file.ext - converts it to something that rundll32.exe understands - namely \\SOMECOMPUTER\sharename\path\to\file.ext - and feeds it to the rundll32.exe URL handler. Now you can click on smb:// links and the appropriate associated program will open the file.

The last step is telling Opera that it should handle smb:// links as well. Go to File -> Preferences -> Programs and Paths. Hit Add, type smb in the Protocol field. Your custom handler should now appear in the Open with default application text box. Select it, and you're done.

This procedure was tested with Windows 2000 SP4, the binaries supplied above and Opera version 7.22. Comments or suggestions can be mailed to walter AT djcvt DOT net. I'd love to hear the simple solution that isn't such a kludge.