Zend certified PHP/Magento developer

How is a batch file (`.cmd` / `.bat`) file executed on Windows?

Context

On Windows, the application responsible for opening a given file type (identified by its extension) is resolved using file associations defined (among a few other places) in HKEY_CLASSES_ROOT.

Usually, if I wanted to make a file with a given extension executable, I’d set its file association to the preferred interpreter program. For example, if I wanted to make .ps1 files execute in PowerShell just by invoking them, I’d add HKEY_CLASSES_ROOT.ps1 pointing to some file type and then in HKEY_CLASSES_ROOT<filetype>shellopencommand, write the interpreter and arguments to use (e.g. powershell.exe "%1").

Question

I always assumed that batch files (.cmd/.bat) are associated the same way. However, upon checking HKEY_CLASSES_ROOTcmdfileshellopencommand, the value is "%1" %*, which is the same as for .exe files. This suggests that execution of batch files is handled through another mechanism.

However, unlike with .exe, you cannot pass a batch file path to CreateProcess directly. According to a ProcMon trace of a file manager invoking a batch file, the CreateProcess call already invokes cmd.exe with the batch file as an argument.

This would lead me to believe that execution of batch files is handled somewhere inside the Win32 library code. Is that correct?

Bonus question: Why are batch files not handled using standard file associations, like .vbs and other script files that are supported by default?


Random observation: only the following file extensions are handled by calling "%1" %*: .exe, .com, .bat/.cmd, .pif (at least on my computer)