TC 11.57 Right-click "Run as administrator" on .cmd file will fail if filename contains ()

The behaviour described in the bug report is either by design, or would be far too complex/time-consuming to be changed

Moderators: petermad, Stefan2, Hacker

Post Reply
probica
Junior Member
Junior Member
Posts: 3
Joined: 2025-01-18, 20:46 UTC

TC 11.57 Right-click "Run as administrator" on .cmd file will fail if filename contains ()

Post by *probica »

Total Commander 11.57 will fail to "Run as Administrator" .CMD or .BAT files that contain brackets, for example:
Test(test).cmd will fail executing while Test.cmd will not.
It does not matter what file contains, only how it is named.
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 53149
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: TC 11.57 Right-click "Run as administrator" on .cmd file will fail if filename contains ()

Post by *ghisler(Author) »

This seems to be a Windows bug, so I cannot fix it. Try the same in Explorer (right click, Run as Administrator).

Running the command
*"Test(test).cmd"
with Shift+Enter from the command line seems to work, though.

Moderator message from: ghisler(Author) » 2026-06-04, 08:06 UTC

Moved to will not be changed
Author of Total Commander
https://www.ghisler.com
User avatar
white
Power Member
Power Member
Posts: 6941
Joined: 2003-11-19, 08:16 UTC
Location: Netherlands

Re: TC 11.57 Right-click "Run as administrator" on .cmd file will fail if filename contains ()

Post by *white »

Isn't that dependent on whether or not the path contains a space or not?



The fun part comes in when you also create a file named "Test^(test^).cmd" and when you run this file as administrator. Then it can happen that the wrong file is executed ;)

Create these batch files in a path that does not contain spaces:

Test(test).cmd

Code: Select all

@echo off
echo Batch file started: "Test(test).cmd"
pause
Test^(test^).cmd

Code: Select all

@echo off
echo Batch file started: "Test^(test^).cmd"
pause
When running "Test^(test^).cmd" as administrator, "Test(test).cmd" is executed instead.



Let's look in the registry and see what happens.
  • HKEY_LOCAL_MACHINE\SOFTWARE\Classes\cmdfile\shell\open\command

    Code: Select all

    "%1" %*
    Seems to cause execution of:

    Code: Select all

    c:\windows\System32\cmd.exe /C ""%1" %*"
  • HKEY_LOCAL_MACHINE\SOFTWARE\Classes\cmdfile\shell\runas\command

    Code: Select all

    %SystemRoot%\System32\cmd.exe /C "%1" %*
    Seems to cause execution of:

    Code: Select all

    "c:\windows\System32\cmd.exe" /C "%1" %*
So it seems the last registry setting is wrong. It is missing a pair of quotes. To fix it, add the quotes:
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\cmdfile\shell\runas\command

Code: Select all

%SystemRoot%\System32\cmd.exe /C ""%1" %*"
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 53149
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: TC 11.57 Right-click "Run as administrator" on .cmd file will fail if filename contains ()

Post by *ghisler(Author) »

Maybe use /S/C instead of /C ?
Author of Total Commander
https://www.ghisler.com
User avatar
white
Power Member
Power Member
Posts: 6941
Joined: 2003-11-19, 08:16 UTC
Location: Netherlands

Re: TC 11.57 Right-click "Run as administrator" on .cmd file will fail if filename contains ()

Post by *white »

ghisler(Author) wrote: 2026-06-04, 13:03 UTC Maybe use /S/C instead of /C ?
Adding the quotes to the registry value (as described) solves it. There's no need to add /S in that case because the outer quotes will be stripped anyway when there are more than 1 pair of quotes. As mentioned, that's how Microsoft is doing it when running a batch file non-elevated.
Post Reply