Opening smb:// links on windows

10

1

Is there any way to make Windows (10 preferably) explorer to open smb protocol URI? Like smb://1.2.3.4/file.txt

I'm in a diverse environment of operating systems (mostly windows, mac and linux) and also web services we're using (slack, youtrack) but all our files are sitting on a server with samba share and it's hard to have clickable links that all can access.

We have two options for unification:

  1. The Windows way - file://X:/
  2. The Unix way? - smb://1.2.3.4/

I've found it's easier to use the smb links with web tools, slack recognizes them, mac and linux open them fine, it's just that windows are refusing to recognize the protocol, although the address itself works.

Eskel

Posted 2016-04-11T16:16:35.303

Reputation: 291

2

[so] dupe: How do I register a custom URL protocol in Windows?

– DavidPostill – 2016-04-11T16:56:15.270

[so] dupe: how do I create my own URL protocol? (e.g. so://…) – DavidPostill – 2016-04-11T16:57:05.977

1

MSDN: Registering an Application to a URI Scheme

– DavidPostill – 2016-04-11T16:59:17.083

1Note: The Windows way assumes that 1.2.3.4 is mounted as X:. The more reliable way to do it is \1.2.3.4. – Duncan X Simpson – 2016-04-11T19:31:07.753

Answers

9

Thanks DavidPostill for pointing me into the right direction. Here is what I did:

Registry file (smb.reg):

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\smb]
"URL Protocol"=""
@="URL:SMB Protocol"

[HKEY_CLASSES_ROOT\smb\DefaultIcon]
@="explorer.exe,1"

[HKEY_CLASSES_ROOT\smb\shell]
[HKEY_CLASSES_ROOT\smb\shell\open]
[HKEY_CLASSES_ROOT\smb\shell\open\command]
@="\"C:\\OpenLink\\openLink.bat\" \"%1\""

Batch file (openLink.bat):

@echo off
set str=%1
set str=%str:smb:=%
set str=%str:/=\%
explorer.exe %str%

And it works great. :)

Eskel

Posted 2016-04-11T16:16:35.303

Reputation: 291

i saved your registry code as a .reg file but it can't be installed, can you help me to install it? sorry for stupid request, i'm not familiar to this kind of things. – Luke – 2016-10-24T15:21:28.883

1@LongTTH i know its late but the reg header depends on your os. So you may have to check for the first line that it suites to your os. – Dwza – 2018-01-30T08:02:46.570

3

If your SMB links contain spaces, you can use the following improved batch script in Eskel's answer:

@echo off

set str=%1
set str=%str:smb:=%
set str=%str:/=\%

setlocal EnableDelayedExpansion
set str=!str:%%20= !

rem echo %str% & pause

explorer.exe %str%

oberlies

Posted 2016-04-11T16:16:35.303

Reputation: 430

1

For whatever reason, in Windows 10, invoking explorer.exe as detailed in the other answers here didn't work; it would always just open up the user's Documents location. Instead, I found that start "" %str% worked.

For completeness, then, this is the openLink.bat file I got working, based on oberlies' improvement on Eskel's original answer:

@echo off

set str=%1
set str=%str:smb:=%
set str=%str:/=\%

setlocal EnableDelayedExpansion
set str=!str:%%20= !

rem echo %str% & pause
start "" %str%

And then this is the .reg file I used:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\smb]
"URL Protocol"=""
@="URL:SMB Protocol"

[HKEY_CLASSES_ROOT\smb\DefaultIcon]
@="explorer.exe,1"

[HKEY_CLASSES_ROOT\smb\shell]
[HKEY_CLASSES_ROOT\smb\shell\open]
[HKEY_CLASSES_ROOT\smb\shell\open\command]
@="\"C:\\Windows\\openLink.bat\" \"%1\""

(Which is the same as Eskel's original except that I didn't want to create another folder junking up the listings on the C: drive so I just tossed the batch file into the Windows folder. As a bonus, this puts it in the Windows $PATH, or %PATH% I suppose.)

keithzg

Posted 2016-04-11T16:16:35.303

Reputation: 11

1

the URL you call on Windows (any of the mentioned web browsers) is:

file://///IP/Share

(IP is IP address or host, share is a valid SMB share, accessible anonymously or through authentication)

Edu

Posted 2016-04-11T16:16:35.303

Reputation: 11

Confirmed working on Windows 10! – Colin – 2019-08-21T23:50:00.167

0

The easiest way to go on Windows is, assuming your browser has Javascript enabled, like this:

JS: if (navigator.userAgent.indexOf('Windows')!=-1) { document.getElementById('objDiv').innerHTML='SMB location '; }

I assume you have eg. a DIV tag with id=objDiv. Notice that, although modern browsers like Chrome, Firefox, IE 11, Opera (does anyone still use it ?) will prevent you from navigating from "non-FILE:/// URIs" like HTTP, HTTPS to a "file:///" based URI, you could try writing the URL to the page if you cannot access it, (you could try window.location and upon error, write to the page and ask the user to copy the URL and paste it into the address bar of his browser). Advantage: you dont need to ask for installation of anything. Disadvantage: users will always have to copy and paste stuff on the browser address bar.

Registering the SMB:// URL Protocol is ok, but the script provided by our friend assumes you have 'Administrator' level access, and every time you try to reference this protocol, the browser will prompt (unless of course you change settings to it wont ask about this particular protocol.).

A workaround to the REG script is, to replace :

HKCR with HKCU\Software\Classes ...the 'PATH' environment variable for the current user (which doesnt require Administrator access to change) is located at : HKCU\Environment in Windows Registry. (you edit the 'path' REG_SZ or REG_EXPAND_SZ value.)

If you have 'Administrator' access, you can right-click the batch script provided (.bat or .cmd files) and then select the "Run As Administrator" menu option...this is translated (localized) for different languages, but the easiest way to know this menu option is to look at the icon of a shield, on the left side of the option. Advantages: user wont need to copy and paste stuff all the time... Disadvantages: Users will have to install stuff. Also, URL Protocol might contain vulnerabilities, including but not limited to browser security bypass allowing them from being invoked automatically or code/argument injections which could lead to a mess, system compromise, etc.

Note: Successfully tested on Chrome, Firefox and IE 11. Edge doesnt seem to support at all network paths (local paths ok, but again you cannot navigate from remote locations to local folders or files)

hope this further helps and clarifies ;)

Edu

Posted 2016-04-11T16:16:35.303

Reputation: 1