Jared Allard
Jared Allard

Reputation: 933

Add a batch file extension

I Have a want too add in the extension .btm too act just like a batch file, is there any way I could do that and possibly permanently add it into my registry?

Upvotes: 1

Views: 612

Answers (1)

npocmaka
npocmaka

Reputation: 57252

Here's my investigation over the topic

As the simply using assoc will not work .I use a temp file that renames the file with bat extension .There's still room form improvements (e.g. the temp file could be deleted) , but is the only way that I've found to make a file with a different extension to act like /bat/cmd. This does not edit the %PATHEXT% so if you want to call these wiles without extension you'll need to edit by yourself.

First create a bat file that looks like this:

@echo off 
copy "%~nx1"  "%temp%\%~nx1.bat" /Y >nul 
"%temp%\%~nx1.bat"  %2

and save it as "%ProgramFiles%\caller\caller.bat"

Then create a .bat file like this and run it as administrator:

Windows Registry Editor Version 5.00

;REM
;REM -------- THIS IS INSTALLMENT PART --------
;REM
;@ECHO OFF
;CLS
;BREAK
;BREAK -- CREATING THE EXTENSION CALLER 
;BREAK
;
;echo @echo off > %temp%\caller.temp
;echo copy "%%~nx1"  "%%temp%%\%%~nx1.bat" /Y ^>nul >>%temp%\caller.temp
;echo "%%temp%%\%%~nx1.bat"  %%2>>%temp%\caller.temp
;
;md "%ProgramFiles%\caller" >nul 2>&1
;copy "%temp%\caller.temp"  "%ProgramFiles%\caller\caller.bat" /Y >nul 2>&1
;
;BREAK
;BREAK -- CALLING REGEDIT
;BREAK
;
;REGEDIT.EXE /S "%~f0"
;GOTO :EOF
;
;REM
;REM -------- HERE STARTS THE REGISTRY PART --------
;REM




;this links the information for the extension to
;HKEY_CLASSES_ROOT\btmfile
[HKEY_CLASSES_ROOT\.btm]
@="cmffile"

;this is used by windows search
;it's value indicates that it contains only text
[HKEY_CLASSES_ROOT\.btm\PersistentHandler]
@="{5e941d80-bf96-11cd-b579-08002b30bfeb}"

;This is the other part of the registry which is edited
;here is contained the actual information
[HKEY_CLASSES_ROOT\btmfile]

[HKEY_CLASSES_ROOT\btmfile\DefaultIcon]
@="%SystemRoot%\\System32\\imageres.dll,-68"

[HKEY_CLASSES_ROOT\btmfile\shell]

[HKEY_CLASSES_ROOT\btmfile\shell\Run]

;Unfortunately does not work with %ProgramFiles%
[HKEY_CLASSES_ROOT\btmfile\shell\Run\command]
@="\"C:\\Program Files\\caller\\caller.bat\" \"%1\" %*"

Upvotes: 3

Related Questions