Opening smb:// links on windows
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Melt
--
Chapters
00:00 Opening Smb:// Links On Windows
01:06 Accepted Answer Score 12
01:41 Answer 2 Score 4
01:59 Answer 3 Score 2
03:01 Answer 4 Score 2
03:24 Answer 5 Score 0
06:11 Thank you
--
Full question
https://superuser.com/questions/1064142/...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#windows #networking #samba
#avk47
ACCEPTED ANSWER
Score 12
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. :)
ANSWER 2
Score 4
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%
ANSWER 3
Score 2
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.)
ANSWER 4
Score 2
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)
ANSWER 5
Score 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 ;)