start cmd.exe minimized/hidden via contextmenu

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?

Janik H

Posted 2015-11-30T05:57:18.387

Reputation: 43

1Might 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 – 2015-11-30T10:08:31.573

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 – 2015-11-30T10:12:42.027

Answers

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

JosefZ

Posted 2015-11-30T05:57:18.387

Reputation: 9 121

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 – 2015-12-01T05:02:55.140