start cmd.exe minimized/hidden via contextmenu

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?


Solution 1:

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}"