Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

REQ: tcmdhere.btm mod

Apr
1,802
16
rem This batch file adds the "TCMD prompt here" entry to Windows Explorer

I'd like to add a verb to the directory / drive context menu - so it can allow TCMD to "run as administrator" in the specified location. I am just not clear how to modify the tcmdhere.btm to do it - and selectively remove the entries from the registry. Any help / guidance greatly appreciated....

TCC 16.03.54 x64 Windows 7 [Version 6.1.7601]
 
It's too bad that you can't specify a shortcut as the command for a shell verb; that would make this easier. This should work.

In TCMD's home directory, make a copy of TCMD.EXE called, say, TCMDUP.EXE. In the "Properties" for TCMDUP.EXE ... "Compatibility" ... specify "Run as administrator". Then either edit tcmdhere.btm to change "tcmd.exe" to "tcmdup.exe" and run it. Or run tcmdhere.btm first and later edit the registry to make the same change.

You could also use either editing method to change the context menu text from "TCMD prompt here" to whatever you like.

Of course,

1. you'll get the UAC prompt
2. you'll have to (should) update TCMDUP.EXE whenever you update TCMD.EXE
 
rem This batch file adds the "TCMD prompt here" entry to Windows Explorer

I'd like to add a verb to the directory / drive context menu - so it can allow TCMD to "run as administrator" in the specified location. I am just not clear how to modify the tcmdhere.btm to do it - and selectively remove the entries from the registry. Any help / guidance greatly appreciated....

Here's a stab at it.
 

Attachments

  • tcchere.btm
    1.8 KB · Views: 239
I think he wanted TCMD.

That is why I titled the message thread tcmdhere.btm - NOT tcchere.btm - assuming the latter even exists in the destination foler along with TCC / TCMD / DLLs / etc...
 
Last edited:
That is why I titled the message thread tcmdhere.btm - NOT tcchere.btm - assuming the latter even exists I nthe destination foler along with TCC / TCMD / DLLs / etc...

Ah. My mistake. But the same approach should work: use the RUNAS shell verb.
 

Attachments

  • tcmdhere.btm
    1.9 KB · Views: 252
Well, if I Google RunAs "Shell Verb", the first hit I get is:
Can I make a shell context action run as administrator?
There's a RegEdit script.

(The fourth hit is MSDN, which you might expect would be a good source of info; but the only mention of "RunAs" on that page is a user complaining about its obvious absence.)

From the superuser link: "How do I add multiple verbs that need to run as administrator?" from Doub on Apr 5, 2019 at 22:38. The reply was "@Doub use cascading context menus. Inside you can put many runas'!" by @ScienceDiscoverer on Jun 10, 2022 at 21:50.

Reason why i bring this up is that i'd love to have the code to use a cascading context menu to handle the currnt GM release (i.e. v29) and the one that is newer but not GM yet. (i.e. v30). Is it possible to do a CCM for my modified tcmdhere_mod.btm ?
 
The trick is to create a REG_SZ value named "subcommands" under your TCMD entry.
Then you can add your submenus. For example, if you want "TCMD prompt here >" and then TC29 and TC30 as submenu options,
instead of a "command" key under TCMD, you create another "shell" key.

Code:
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\runas]
"subcommands"=""

[HKEY_CLASSES_ROOT\Directory\shell\runas\shell]

[HKEY_CLASSES_ROOT\Directory\shell\runas\shell\TC29]
@="TCMD v29 &prompt here"
"HasLUAShield"=""

[HKEY_CLASSES_ROOT\Directory\shell\runas\shell\TC29\command]
@="C:\\TC29\\tcmd.exe /D \"%L\""

[HKEY_CLASSES_ROOT\Directory\shell\runas\shell\TC30]
@="TCMD v30 &prompt here"
"HasLUAShield"=""

[HKEY_CLASSES_ROOT\Directory\shell\runas\shell\TC30\command]
@="C:\\TC30\\tcmd.exe /D \"%L\""

[HKEY_CLASSES_ROOT\Drive\shell\runas]
"subcommands"=""

[HKEY_CLASSES_ROOT\Drive\shell\runas\shell]

[HKEY_CLASSES_ROOT\Drive\shell\runas\shell\TC29]
@="TCMD v29 &prompt here"
"HasLUAShield"=""

[HKEY_CLASSES_ROOT\Drive\shell\runas\shell\TC29\command]
@="C:\\TC29\\tcmd.exe /D \"%L\""

[HKEY_CLASSES_ROOT\Drive\shell\runas\shell\TC30]
@="TCMD v30 &prompt here"
"HasLUAShield"=""

[HKEY_CLASSES_ROOT\Drive\shell\runas\shell\TC30\command]
@="C:\\TC30\\tcmd.exe /D \"%L\""

The above is a regedit file that can be imported that is using hard coded paths to my installations of TC29 & TC30. @Charles Dye uses the %_cmdspec variable in his script to locate the currently running version of TCMD. Mine is more brute force.

1684166986138.png
 
I haven't been following this thread. What is it that makes the specified command run elevated? Is it simply the key name "shell\runas"? And what happens when you run it ... do you go directly to a UAC prompt, or do you have to enter user information?
 
This is mine - corrected for location of tcmd.exe and taking a stab at what comment char is...
Code:
Windows Registry Editor Version 5.00

:::::::::::::::::::::::::::
:::::::: Please see https://jpsoft.com/forums/threads/req-tcmdhere-btm-mod.5813/#post-65313
:::::::::::::::::::::::::::

:::::::: DIRECTORY ::::::::

[HKEY_CLASSES_ROOT\Directory\shell\runas]
"TCMD RunAs"=""

[HKEY_CLASSES_ROOT\Directory\shell\runas\shell]

:::::::: v29       ::::::::

[HKEY_CLASSES_ROOT\Directory\shell\runas\shell\TC29]
@="TCMD v29 prompt here (&Admin)"
"HasLUAShield"=""

[HKEY_CLASSES_ROOT\Directory\shell\runas\shell\TC29\command]
@="C:\\Program Files\\JPSoft\\TCMD29\\\tcmd.exe /D \"%L\""

:::::::: v30       ::::::::

[HKEY_CLASSES_ROOT\Directory\shell\runas\shell\TC30]
@="TCMD v30 prompt here (&Admin)"
"HasLUAShield"=""

[HKEY_CLASSES_ROOT\Directory\shell\runas\shell\TC30\command]
@="C:\\Program Files\\JPSoft\\TCMD30\\tcmd.exe /D \"%L\""

:::::::: DRIVE     ::::::::

[HKEY_CLASSES_ROOT\Drive\shell\runas]
"TCMD RunAs"=""

[HKEY_CLASSES_ROOT\Drive\shell\runas\shell]

:::::::: v29       ::::::::

[HKEY_CLASSES_ROOT\Drive\shell\runas\shell\TC29]
@="TCMD v29 prompt here (&Admin)"
"HasLUAShield"=""

[HKEY_CLASSES_ROOT\Drive\shell\runas\shell\TC29\command]
@="C:\\Program Files\\JPSoft\\TCMD29\\\tcmd.exe /D \"%L\""

:::::::: v30       ::::::::

[HKEY_CLASSES_ROOT\Drive\shell\runas\shell\TC30]
@="TCMD v30 prompt here (&Admin)"
"HasLUAShield"=""

[HKEY_CLASSES_ROOT\Drive\shell\runas\shell\TC30\command]
@="C:\\Program Files\\JPSoft\\TCMD30\\tcmd.exe /D \"%L\""
 
I'm sorry, but but I honestly don't know when I'll be able to mess with this. But anyone else is welcome to modify that batch file -- I don't claim any ownership over it!

.... Or maybe not just modify, but rewrite from scratch. I had no idea that it was possible to create submenus for shell/runas. Taking proper advantage of that little trick might involve a total rewrite.
 
I haven't been following this thread. What is it that makes the specified command run elevated? Is it simply the key name "shell\runas"? And what happens when you run it ... do you go directly to a UAC prompt, or do you have to enter user information?
I believe it is the equivalent of "Run as Administrator" when you choose something from the Start menu.
 
Thanks Scott.

Charles ... really! Do you mean no UAC prompt if I have admin rights? That's contrary to my expectation.

Here's a barebones script (below) if anyone wants to mess with it. It also does directory\background and seems to do the right thing (see further below). Remove the four references to "test\" to get the real thing.

Code:
@echo off
do key in /L test\Directory test\Directory\Background test\Drive test\Folder
    if %@regcreate["HKCR\%key\Shell\TCC\command"] NE 0 (echoerr Failed to create %key & quit)
    if %@regset[HKCR\"%key\Shell\TCC\",REG_SZ,TCCHere] NE 0 (echoerr Failed to update HKCR\%key\Shell\TCC\ & quit)
    if %@regset[HKCR\"%key\Shell\TCC\command\",REG_SZ,"%_cmdspec" /D "%%V"] NE 0 (echoerr Failed to update %key\Shell\TCC\command\ & quit)
enddo

echo.
echo The Windows Explorer context menus have been updated.

Code:
hkcr\test
  Directory
    Background
      Shell
        TCC
           : REG_SZ : TCCHere
          command
             : REG_SZ : "D:\tc30\TCC.EXE" /D "%V"
    Shell
      TCC
         : REG_SZ : TCCHere
        command
           : REG_SZ : "D:\tc30\TCC.EXE" /D "%V"
  Drive
    Shell
      TCC
         : REG_SZ : TCCHere
        command
           : REG_SZ : "D:\tc30\TCC.EXE" /D "%V"
  Folder
    Shell
      TCC
         : REG_SZ : TCCHere
        command
           : REG_SZ : "D:\tc30\TCC.EXE" /D "%V"

Doing HKCR\Folder also gives you TCCHere for this.

1684174069321.png


Using it takes you here.

Code:
\\wsl.localhost\ubuntu> dir

 Directory of  \\wsl.localhost\Ubuntu\*

2023-05-15  14:08         <DIR>    .
2023-05-15  14:08         <DIR>    ..
2021-01-20  22:04         <DIR>    bin
2019-05-21  10:42         <DIR>    boot
2023-05-15  14:07         <DIR>    dev
2023-05-15  14:08         <DIR>    etc
2019-07-04  00:46         <DIR>    home
2021-05-05  22:04         <DIR>    lib
2021-05-05  22:04         <DIR>    lib64
2019-04-10  12:35         <DIR>    lost+found
2019-05-21  10:39         <DIR>    media
2022-08-31  12:23         <DIR>    mnt
2019-05-21  10:39         <DIR>    opt
2023-05-15  14:08         <DIR>    proc
2019-09-08  11:22         <DIR>    root
2023-05-15  14:08         <DIR>    run
2019-07-04  00:51         <DIR>    sbin
2019-03-21  05:55         <DIR>    snap
2019-05-21  10:39         <DIR>    srv
2023-05-15  14:07         <DIR>    sys
2022-09-04  12:28         <DIR>    tmp
2019-05-21  10:39         <DIR>    usr
2019-05-21  10:42         <DIR>    var
2022-12-14  08:38         644,432  init
2021-01-20  23:36               6  v
             644,438 bytes in 2 files and 23 dirs
     254,508,777,472 bytes free
 
Just a humorous (?) note. Using WSL (as in my previous post) gives you the LsxxManager service and a bunch of WSL-related processes, including vmwp.exe.

In case you're tempted, don't try taskend /f vmwp. I tried it and got the modern version of the BSOD (which is, in fact, blue). After several minutes of collecting information to send to Microsoft and a restart, everything was OK.

sc stop LxssManager gets rid of all those processes. I don't know if they would have gone away on their own.
 
FWIW, these go away on their own after a period of non-use leaving only the LxssManager service running.

Code:
vmwp.exe
vmmem
wslhost.exe
conhost.exe
 
@vefatica the ask was to get submenus for the "Run as Administrator" "prompt here" menus so you could choose which TCMD you wanted to run.
Code:
@echo off
setlocal
set tcmdver=TC%_vermajor
set tcmdexe=%@path[%_cmdspec]tcmd.exe

do key in /L Directory Drive Folder
    if %@regcreate["HKCR\%key\Shell\runas\shell\%[tcmdver]\command"] NE 0 (echoerr Failed to create %key & quit)
    if %@regset["HKCR\%key\Shell\runas\subcommands",REG_SZ,] NE 0 (echoerr Failed to update %key\Shell\runas\ & quit)
    if %@regset["HKCR\%key\Shell\runas\shell\%[tcmdver]\",REG_SZ,Tcmd v%_vermajor Here] NE 0 (echoerr Failed to update %key\Shell\runas\shell\%[tcmdver] & quit)
    if %@regset["HKCR\%key\Shell\runas\shell\%[tcmdver]\HasLUAShield",REG_SZ,] NE 0 (echoerr Failed to update %key\Shell\runas\shell\%[tcmdver] & quit)
    if %@regset["HKCR\%key\Shell\runas\shell\%[tcmdver]\command\",REG_SZ,"%tcmdexe" /D "%%L"] NE 0 (echoerr Failed to update %key\Shell\runas\shell\%[tcmdver] & quit)
enddo

echo.
echo The Windows Explorer context menus have been updated.
 
It will append each version you run the script in. So it'll create a V29 entry when run in v29 and a V30 entry when run from v30.
 
Thanks Scott.

Charles ... really! Do you mean no UAC prompt if I have admin rights? That's contrary to my expectation.

Here's a barebones script (below) if anyone wants to mess with it. It also does directory\background and seems to do the right thing (see further below). Remove the four references to "test\" to get the real thing.

Code:
@echo off
do key in /L test\Directory test\Directory\Background test\Drive test\Folder
    if %@regcreate["HKCR\%key\Shell\TCC\command"] NE 0 (echoerr Failed to create %key & quit)
    if %@regset[HKCR\"%key\Shell\TCC\",REG_SZ,TCCHere] NE 0 (echoerr Failed to update HKCR\%key\Shell\TCC\ & quit)
    if %@regset[HKCR\"%key\Shell\TCC\command\",REG_SZ,"%_cmdspec" /D "%%V"] NE 0 (echoerr Failed to update %key\Shell\TCC\command\ & quit)
enddo

echo.
echo The Windows Explorer context menus have been updated.
[omitted]

How would I code the handling if...

Code:
iff "%1" == "/U" then
endiff

please?
 
I rearranged things a bit. This (below) seems to work (see the test, further below).

Code:
@echo off
setlocal
set places=test\Directory test\Directory\Background test\Drive test\Folder

iff "%1" == "/U" then
    do key in /L %places
        if %@regdelkey["HKCR\%key\Shell\TCC"] NE 1 (echoerr Failed to remove HKCR\%key\Shell\TCC & quit)
    enddo
    echo TCCHere removed from the context menu
    quit
endiff

do key in /L %places
    if %@regcreate["HKCR\%key\Shell\TCC\command"] NE 0 (echoerr Failed to create HKCR\%key\Shell\TCC\command & quit)
    if %@regset[HKCR\"%key\Shell\TCC\",REG_SZ,TCCHere] NE 0 (echoerr Failed to update HKCR\%key\Shell\TCC\ & quit)
    if %@regset[HKCR\"%key\Shell\TCC\command\",REG_SZ,"%_cmdspec" /D "%%V"] NE 0 (echoerr Failed to update %key\Shell\TCC\command\ & quit)
enddo

echo.
echo TCCHere added to the context menu

Code:
c:\users\vefatica\desktop\archive> tcchere.btm

TCCHere added to the context menu

c:\users\vefatica\desktop\archive> regdir /v /d hkcr\test
hkcr\test
  Directory
    Background
      Shell
        TCC
           : REG_SZ : TCCHere
          command
             : REG_SZ : "D:\tc30\TCC.EXE" /D "%V"
    Shell
      TCC
         : REG_SZ : TCCHere
        command
           : REG_SZ : "D:\tc30\TCC.EXE" /D "%V"
  Drive
    Shell
      TCC
         : REG_SZ : TCCHere
        command
           : REG_SZ : "D:\tc30\TCC.EXE" /D "%V"
  Folder
    Shell
      TCC
         : REG_SZ : TCCHere
        command
           : REG_SZ : "D:\tc30\TCC.EXE" /D "%V"

c:\users\vefatica\desktop\archive> tcchere.btm /u
TCCHere removed from the context menu

c:\users\vefatica\desktop\archive> regdir /v /d hkcr\test
hkcr\test
  Directory
    Background
      Shell
    Shell
  Drive
    Shell
  Folder
    Shell
 

Similar threads

Back
Top