Good day, gentlemen! I wrote a class here that allows you to print images in the console. I wanted to make something like my own image format, which, when opened, would print a photo in the console. I have, say, a file, inside of which there is a cmd command that prints a photo. I changed the extension to some kind of my own. Say ".cmdpng". How do I associate this extension with a Windows script?

    2 answers 2

    Create in the registry the association of your .cmdpng extension with the cmdfile format used for the .cmd extension.

    We reuse the existing format because the processing of the one-in-one file type is the same as the existing one.

    To create an association, you must create the HKEY_CLASSES_ROOT\.cmdpng and set its default key to cmdfile .

    • I tried your way, it does not work. "Unable to run this application on your PC." Windows 10 Pro x64 - Dmitry

    In Windows, it is not possible to assign an arbitrary extension as an executable file. However, there is one solution found here .

    The essence of the solution lies in the fact that we create a batch file that takes as the first parameter the name of a file with any extension, creates a copy of this file with the extension .cmd and executes it.

    Using the ASSOC and FTYPE commands, FTYPE associate .cmdpng with this batch file.


    Turnkey solution

    Save the code to install.cmd .

     @echo off ( echo @echo off echo COPY "%%~nx1" "%%temp%%\%%~nx1.cmd" /Y ^>nul echo CALL "%%temp%%\%%~nx1.cmd" %%* echo DEL /Q "%%temp%%\%%~nx1.cmd" ) > %temp%\caller.cmd ASSOC .cmdpng=cmdpngfile FTYPE cmdpngfile=%temp%\caller.cmd %%1 %%* 

    Run install.cmd as administrator (needed for ASSOC and FTYPE ). And you can run files with the extension .cmdpng .