2

I've created a shortcut to the contextmenu by adding a new registryentry with this RE_SZ Key: cmd.exe start /min /c echo %1|clip

This allows me to copy the path of the rightclicked file.

BUT: It will always open a cmd window for a short time.

How can I hide this cmd window?

2
  • 1
    Might be suitable for you: hold down the Shift key as you right-click the file/folder (or even select), and then choose Copy As Path.
    – JosefZ
    Commented Nov 30, 2015 at 10:08
  • Thank you for your reply, but the shortcut should show a special program to send to (kodi) and with the standard "Copy path" menu it won't work. Do you know the Registrykey which stored the Copy as Path context menu? This would be interesting, how that works.
    – Janik H
    Commented Nov 30, 2015 at 10:12

1 Answer 1

3

Hide the cmd window using ShellExecute method. Next registry setting works for a single file:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\shell\MyCopyAsPath]

[HKEY_CLASSES_ROOT\*\shell\MyCopyAsPath\command]
@="wscript D:\\VB_scripts\\SU\\1007076.vbs \"%1\""

where D:\VB_scripts\SU\1007076.vbs reads as follows:

option explicit
On Error GoTo 0

If WScript.Arguments.Count = 1 Then
  Dim objShell
  Set objShell = CreateObject("shell.application")
  objShell.ShellExecute "cmd.exe" _
    , "/C echo(" & WScript.Arguments(0) & "|clip", "", "open", 0
  Set objShell = nothing
Else
  MsgBox "wrong numer of parameters"
End If
Wscript.Quit

Above script returns full path of a single file (or target of a file shortcut) and adds CRLF (carriage return and linefeed). You could omit the CRLF using set /P trick as follows:

  objShell.ShellExecute "cmd.exe" _
    , "/C <NUL set /P =""" & WScript.Arguments(0) & """|clip", "", "open", 0

Next improvement to surround the path in a pair of " double quotes:

  objShell.ShellExecute "cmd.exe" _
    , "/C <NUL set /P =""""" & WScript.Arguments(0) & """""|clip", "", "open", 0

FYI, here is registry key which stored the Copy as Path context menu:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\shell\CopyAsPathMenu]
"ProgrammaticAccessOnly"="Apartment"

[HKEY_CLASSES_ROOT\*\shell\CopyAsPathMenu\DropTarget]
"CLSID"="{f3d06e7c-1e45-4a26-847e-f9fcdee59be0}"
1
  • Thank you very much for this! Although I have to create a file (VBScript) but it really works! Great! And also a nice explanation! :)
    – Janik H
    Commented Dec 1, 2015 at 5:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .