Welcome!

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

SignUp Now!

How to? Deinstalling TC/reinstating execution of bat files by cmd in Win7

Hello
Windows 7

1) History:
I've installed TC and made it default handeler for bat and cmd files. It turned out that when I run simple bat file for Far
--------------
c:\FAR3\Far.exe
exit
--------------
it does not work properly - apparently Far starts but I don't see any panels.

I've tried to amend the shortcut icon
 
You want to revert .BAT and .CMD files to CMD‍.EXE? Try this:

Code:
assoc .bat=batfile
ftype batfile="%%1" %%*

assoc .cmd=cmdfile
ftype cmdfile="%%1" %%*
 
Last edited:
I've installed TC and made it default handeler for bat and cmd files. It turned out that when I run simple bat file for Far
--------------
c:\FAR3\Far.exe
exit
--------------
it does not work properly - apparently Far starts but I don't see any panels.
Is that Windows 10?
Does Far starts normally if you don't use bat file?
 
Thanks Charles. Do you know what these command actually do in the register ?

I ask because after all the rebootings/attempts to fix I now has the situation where I can't execute bat files/cmd files. I've saved your suggested commands into text file with .bat extenstion but when I click on it I have only cmd prompt with no evidence of whether the commands have been executed. If I rename it to .cmd then it asks which program to use to run it.

At the end of the day I can certainly try to retype all the quotes, etc. without mistakes, but may be there is more elegant solution. - OH, it did not work: access denied...

As to Far - I have Windows 7, it worked fine, but I remember it is a console application which adds some complications.
 
Finally I ran cmd-.-exe with administrative priviledge and executed suggested commands (fixed typo in fype). Still I get only cmd prompt openned in the working directory specified in the shortcut. When I type exit the windows closes which suggests that bat files does not load the actual programs like Far...

Then I typed the name of the bat file in the cmd-.-exe prompt (openned in the working directory specified in the shortcut) - then everything worked. Are there any mistakes in the command "ftype batfile="%%1" %%*" ?
 
Sergey, look in the installation directory and read the files TCCBATCH.BTM and TCMDBATCH.BTM. One of these will show you what happens in the registry.

TCCBATCH.BTM will also let you make CMD the handler for .BAT and .CMD. I use TCC only for .BTM.

I don't know how well FAR will work with TCMD (the tabbed, GUI program) but here, it starts OK using TCC (the console program). I have

Code:
d:\tc26> assoc .btm
.btm=TCC.Batch

d:\tc26> ftype tcc.batch
tcc.batch="D:\tc25\tcc.exe" /c "%1" %*

and 2-clicking on this BTM file starts FAR OK.

Code:
REM this is FAR.BTM
d:\far\far.exe
exit
 
Finally I ran cmd-.-exe with administrative priviledge and executed suggested commands (fixed typo in fype). Still I get only cmd prompt openned in the working directory specified in the shortcut. When I type exit the windows closes which suggests that bat files does not load the actual programs like Far...

Then I typed the name of the bat file in the cmd-.-exe prompt (openned in the working directory specified in the shortcut) - then everything worked. Are there any mistakes in the command "ftype batfile="%%1" %%*" ?

Apologies for the typo.

The associations I gave are the default for Windows, only with the percent signs doubled.
 
Thanks Charles. Do you know what these command actually do in the register ?

To answer your registry question, most file associations are in the registry under HKEY_CLASSES_ROOT. You'll find e.g. a key HKEY_CLASSES_ROOT\.bat which associates .BAT files with the "BATFILE" type. Then there is a key HKEY_CLASSES_ROOT\batfile\shell with various subkeys for different shell verbs, "Open" usually being the most important one. So Windows will look under HKEY_CLASSES_ROOT\batfile\shell\open\command to find the command to open .BAT files.

There's also a key HKEY_CURRENT_USER\Software\Classes with similar stuff; that's for per-user file associations.

I usually find it easier to use ASSOC and FTYPE to manage file associations.
 
I would recommend that (1) TCC (the console program) handle *.BTM, and (2) CMD handle *.BAT and *.CMD. You can arrange that by running TCCBATCH.BTM from TCC.

I also tried a shortcut. Right now I have these on my desktop.
1583341928382.png

Code:
v:\> C:\Users\vefatica\Desktop\
c:\users\vefatica\desktop> type far.btm
REM this is FAR.BTM
d:\far\far.exe
exit

c:\users\vefatica\desktop> shortcut "far.btm - Shortcut.lnk"
Command=C:\Users\vefatica\Desktop\far.btm

The shortcut works OK to start FAR in a console owned by TCC.

If I rename FAR.BTM to FAR.BAT and change the target of the shortcut to "C:\Users\vefatica\Desktop\far.bat" then the shortcut starts FAR in a console owned by CMD.

You don't NEED TCC or CMD. FAR can run in its own console. Just make the shortcut point to FAR.EXE itself.
 
Hello. My current status is the same:

1) I've reinstated TCC to look into TCCBATCH.BTM and TCMDBATCH.BTM files. I vaguely recognise the code: it clearly can change associations from standard to TCC/TCMD, but can it do the opposite and restore the original associations ? One bit of code is very promising in this respect -see below - but does it do what I need ? I've ran both TCCBATCH.BTM and TCMDBATCH.BTM and did not select BAT & CMD assotiations - did this code change the associations to the original one or did it just left them in the original state ?

---------------[I've typed cmd-.- to avoid forum mistake]
iff "%1" == "/U" then
echos Do you want to make CMD the default handler for .BAT and .CMD files [Y/N] ?
inkey /k"yn[enter]" %%var
iff "%var" eq "y" then
ftype batfile="c:\windows\system32\cmd-.-exe" /c "%%1" %%*
ftype cmdfile="c:\windows\system32\cmd-.-exe" /c "%%1" %%*
endiff
quit
endiff
---------------

2) As to "The associations I gave are the default for Windows, only with the percent signs doubled" - I understand that double quotes are for use within bat & cmd files. So why it did not work...

3) My problem apparently is still there, even though I see the
"HKEY_CLASSES_ROOT\.bat which associates .BAT files with the "BATFILE" type" in the register". So the problem must be with the "there is a key HKEY_CLASSES_ROOT\batfile\shell with various subkeys for different shell verbs, "Open" usually being the most important one": I atach my registry key with *.txt extension - does it look correct ?

4) Since my register files does not look right to me ... I've edited
HKEY_CLASSES_ROOT\batfile\shell\open\command to read "%SystemRoot%\System32\cmd-.-exe %1 %*" or
"%SystemRoot%\System32\cmd-.-exe %1 %*"
but it still does not work... How does it read at your computer ?

5) The reason to run Far from bat file is because I need to save the screen resolution, etc. which shortcut does not save if I run far.exe ; I use 800*600 screen resolution.

6) I don't understand "cmd-.-exe" /c "%%1" %%* " syntax - why one need %%1 if %%* means all parameters/does not it include the first one ?
thanks
 

Attachments

Last edited:
"%" is a special symbol in TCC. In a TCC command or BTM file, in order to get one "%" with a TCC command, you must use two. For example,

1583447452237.png


If you're using REGEDIT, you only need one "%".

What do you see in REGEDIT? I see this on Windows 7.

1583448390082.png


Yours,

Code:
[HKEY_CLASSES_ROOT\batfile\shell\open\command]
@=hex(2):22,00,25,00,25,00,31,00,22,00,20,00,25,00,25,00,2a,00,00,00

doesn't look like a string (REG_SZ)
 
Yours,

Code:
[HKEY_CLASSES_ROOT\batfile\shell\open\command]
@=hex(2):22,00,25,00,25,00,31,00,22,00,20,00,25,00,25,00,2a,00,00,00

doesn't look like a string (REG_SZ)

I think that's a REG_EXPAND_SZ. I'd prefer a REG_SZ, but I think REG_EXPAND_SZ should work too — once the doubled percent sign is fixed.
 
I'm attaching a .REG script to set basic associations and Open verbs for .BAT and .CMD. I think this corresponds to the Windows defaults.

Answering the last question:
6) I don't understand "cmd-.-exe" /c "%%1" %%* " syntax - why one need %%1 if %%* means all parameters/does not it include the first one ?

That "%1" is the filename of the file you're clicking. The %*, on the other hand, is any arguments to be passed on to the application program — CMD‍.EXE in this case.
 

Attachments

Code:
ftype batfile="c:\windows\system32\cmd‍.exe" /c "%%1" %%*
ftype cmdfile="c:\windows\system32\cmd‍.exe" /c "%%1" %%*

That's the relevant bit right there.

And while Rex is associating batch files with CMD‍.EXE, that doesn't actually seem to be necessary. The default Windows associations treat .BAT and .CMD files as if they were programs in their own right. I think Windows must "know", at some level below the file-association mechanism, that they should be handled by CMD‍.EXE.

(Note that this code assumes Windows is always installed in C:\WINDOWS! A safer approach would be to use %SYSTEMROOT%.)
 
Dunno. Maybe he was taking the RunAs key as his model...?

While we're asking questions about file associations in the registry: Why does Microsoft specify CMD‍.EXE in the RunAs verb, when it's not needed in the Open verb?
 
Good morning. I've tried to change
[HKEY_CLASSES_ROOT\batfile\shell\open\command] - I think it's original value was
%%1" %%* or something similar

I've changed it to "@=hex(2):22,00,25,00,25,00,31,00,22,00,20,00,25,00,25,00,2a,00,00,00" - it does not work..., but the type of value is reg_expand_sz

Then I've tried to change the value type, but could not find how to do it, so I've created new string and added "@=hex(2):22,00,25,00,25,00,31,00,22,00,20,00,25,00,25,00,2a,00,00,00"
- does not work, though the name of the string is not "Default" but "New parameter1"

I've finally changed value of both "Default" and "New parameter1" strings to "%1" %* - does not work.

So my current questions are: how to change the value type of "Default" string or to rename "New parameter1" to "Default"

I've deleted the first section of the exported [HKEY_CLASSES_ROOT\batfile\shell\open\command] key and deleted first section and then reimported it back, but it failed to change the value type of "Default" string...

--------reg file which did not help--------
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\batfile\shell\open\command]
"@=hex(2):22,00,25,00,25,00,31,00,22,00,20,00,25,00,25,00,2a,00,00,00"
----------------

Finally, I've lloked into Charles' reg file and imported it - does not work, even though now I have the correct value type.
 

Attachments

  • command-after-I've-edited-it.jpg
    command-after-I've-edited-it.jpg
    21.6 KB · Views: 270
  • command-second-edit.jpg
    command-second-edit.jpg
    29.7 KB · Views: 287
  • command-third-edit.jpg
    command-third-edit.jpg
    15.4 KB · Views: 288
Last edited:
I work under the administrative login, but the system always ask if regedit should be allowed to modify the registry. Can it be the case that the changes are made to one copy of the register, but the system still uses another/cashed one even after I reboot the computer ?
 
I think you're going to have to explain what you mean by "doesn't work". Those file associations control what Explorer does when you double-click on a file. When you double-click on a .BAT or .CMD file, does it run in CMD‍.EXE? Or does something else happen? What? Is there an error message? Are you expecting this to affect something other than double-clicking on a batch file in Explorer?

Yes, it's normal for REGEDIT to ask before making changes.

Changes to file associations happen immediately. You shouldn't have to log out or reboot.
 
I am back at the situation which I had earlier on: when I double-click on a .BAT or .CMD file, it opens CMD‍-.-EXE prompt with no error messages and no evidence that CMD‍-.-EXE executed any command. Since I mostly click on the shortcuts CMD‍-.-EXE opens in the working directory specified in the shortcut. If I then type the name of the bat file, it executes properly.

So cmd-.-exe does not receive the argument with the name of bat file to run.
 
I am back at the situation which I had earlier on: when I double-click on a .BAT or .CMD file, it opens CMD‍-.-EXE prompt with no error messages and no evidence that CMD‍-.-EXE executed any command. Since I mostly click on the shortcuts CMD‍-.-EXE opens in the working directory specified in the shortcut. If I then type the name of the bat file, it executes properly.

I don't know what could cause that to happen. If you right-click on a batch file and select "Run as administrator", does that work as expected?
 
Sergey, please make sure you have this.
Code:
v:\> assoc .bat
.bat=batfile

Normally, 2-clicking on a batfile will cause CMD to run it and exit immediately. Unless there is a PAUSE command in the batfile you might not see any output or error messages. Does your batfile have a PAUSE? Does the CMD stay open?
 
Also, do you see the same behavior if you log in as a different user? Or does it work as expected if you log in as a different user?
 
If I can't right-click on a batch file or shortcut - I don't have an option to "Run as administrator"... But your question made me realise that I am not working under the administrative priviledge... I've loged into as administrator and everything works.

Something happened to my memory: before loggin into as administrator I've clicked somewhere and looked into permissions: my current (and lovely setuped) User had only Special priviledges with other priviledges half shaded. Now I had to go into computer management, to local users and there I see a different situation: my current User is member of both Administrators and Debugger Users.

As to normal behaviour of CMD when it runs and exits immediately - my bat files run either Far or MS Access so I would see them. Also the cmd does not close and the command prompt does not show evidence of any commands being executed.

I run bat files or just cmd-.-exe - and assoc does not show any association for bat files... But in the Control Panel default file association Bat files are assotiation with Internal Windows Command (which does not necessarily mean that is is the right option as I saw exactly this when I initially tried to manually reinstate bat file association and has chosen cmd-.-exe).

Finally, I've logged in as the administrator and ran again bat file suggested by Charles (wih typo fixed)
---------------------
assoc .bat=batfile
ftype batfile="%%1" %%*

assoc .cmd=cmdfile
ftype cmdfile="%%1" %%*
pause
---------------------
The command executed properly and association have been reinstated but not in my current User... The reboot did not help.

I've finally recollected where I saw nice interface with all the permissions - right click on the bat file and then Security (picture is attached) - Reading and execution, Reading are allowed for Users. Then I tried (from administrator login) to change user type to Administrative - the OK button does not work...
 

Attachments

  • bat-file-permissions.jpg
    bat-file-permissions.jpg
    43.4 KB · Views: 264
Last edited:
If you manually enter commands into command prompt, DO NOT DOUBLE THE %%'s of positional arguments!!!
This is only needed in batch files.

So,

Code:
ftype batfile="%1" %*

Though I'd prefer

Code:
ftype batfile=%%SystemRoot%%\System32\cmd.еxe /C "%1" %*

Also check the value of %ComSpec% variable

Code:
echo %ComSpec%
should output "%SystemRoot%\System32\cmd.еxe". (With %SystemRoot% expanded to its actual value.)
 
I do not manually enter commands into command prompt as I had to run them in bat files as Administrative (and this option somehow disappeared). So, there is no DOUBLE quotes mistake.

echo %ComSpec% gives the correct output "%SystemRoot%\System32\cmd.еxe" (With %SystemRoot% expanded to its actual value.)

I guess that cmd-.-exe does not run with administrative priviledges and this is why the right clicking on bat files/shortcuts to bat files does not reveal anywhere (whether Properties/Security/Compatibility) an option to run as Administrative

If I press Shift and right click on a program - there is an option to run as Administrative, but not so with bat files...

I looked into register and did not see the traces of suggested changes which were apparently imported earlier on from batreg.zip /unzipped. So intead of clicking on .reg file I've imported it from Regedit (which asked if it should run in Administrative mode - yes). Now changes are there, but the situation is the same.
 
Last edited:
association have been reinstated but not in my current User
Then your current user have custom associations. Check the registry.

Code:
reg query HKEY_CURRENT_USER\Software\Classes\.bat /S
reg query HKEY_CURRENT_USER\Software\Classes\.cmd /S
reg query HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.bat /S
reg query HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.cmd /S
 
1) HKEY_CURRENT_USER\Software\Classes\.bat /S
2) HKEY_CURRENT_USER\Software\Classes\.cmd /S
- these registry entries do not exist



3) reg query HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.bat /S
-------------------------------------------------
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.bat\OpenWithList

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.bat\OpenWithProgids
batfile REG_NONE

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.bat\UserChoice
Progid REG_SZ Applications\cmd-.-exe

--------------------------------------------------


4) reg query HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.cmd /S
--------------------------------------------------
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.cmd\OpenWithList

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.cmd\OpenWithProgids
cmdfile REG_NONE
--------------------------------------------------
 
Evrika !
I've compared registry for Administrative and my loverly User - the entries suggested by
AnrDaemon, I though that Administrative has some extra records/correct data. It turned the other way - my User's register had extra records which I've deleted and everything works again even without rebooting the system.

I've deleted the following:

-----------------------
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.bat\UserChoice
Progid REG_SZ Applications\cmd-.-exe

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.cmd\OpenWithList

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.cmd\OpenWithProgids
cmdfile REG_NONE
-----------------------

What does it mean/at which stage it has emerged ?
 
Back
Top
[FOX] Ultimate Translator
Translate