While cmd.exe can work with UNC paths by using PUSHD \\UNC\Path, I'm attempting to start cmd or a similar command FROM a UNC path. Here's why:
I'm adding a "Map Network Drive Here" to my suite of context menu tools, like "Start Powershell Here" and "Open Command Prompt Here". They add registry keys to the windows registry, and this works great.
As examples, these open a Command Prompt Here:
"cmd /s /k ""VER && TITLE Command Prompt: %1 && PUSHD ""%1"" "" " (For Right-Clicking Folders, works for UNC paths)
"cmd /s /k ""VER && TITLE Command Prompt: %%%CD%%%"" " (For Right-Clicking backgrounds of directories, does not work for UNC paths)
The command is entered as a registry key DWORD, and this works when right clicking a folder:
"net use * ""%1"" " (For Right-Clicking Folders, works for UNC paths)
"net use * ""%%%CD%%%"" " (For Right-Clicking backgrounds of directories, does not work for UNC paths)
I suspect %%%CD%%% is being expanded by cmd.exe, which will not start in a UNC path.
My question is; how do I get the path of the right-clicked 'background of a drive or directory' for both UNC and Windows paths expanded in a registry key for the purposes of passing it to a command?
These will go in HKCR,Directory\Shell\xxx\command and HKCR,Directory\Background\Shell\xxx\command, respectively.
This is an open source project, available on GitHub: https://github.com/Ehryk/ContextMenuTools
%1and%V? – Ehryk Jul 25 '14 at 21:49Directory\Background\Shell;) Because you clicked a blank background there is no parameter for %1. %V is the working directory which is available for a right-click in the blank background of a directory (still the UNC when called by command). You can see a list of these special variables here. %W works too. – Rik Jul 25 '14 at 21:58%Vwas exactly what I needed, and that variable list helped immensely. Thanks! – Ehryk Jul 26 '14 at 05:46