I recently heard from someone that Windows Admins should use CMD logon scripts over BAT logon scripts, as the run or execute faster. Apparently BAT scripts are notoriously slow.
I've done a bit of a google and I can't find any evidence to backup that claim. I'm just wondering if this is a myth or if anyone can know anymore about this?
Best Answer
Regardless of some differences in how
BAT
andCMD
scripts operate as discussed here (by virtue of meritorious Hammer's comment), commands are parsed and executed one after another hereby remembering next command offset (0
at starting point) and opening the script file again from disk for next command.1000
commands in a script would imply1000
disk operations (open-read-close) on the same file. For he sake of exactness, I'm not telling about lines but about commands.That's real source of both
BAT
andCMD
scripts slowness.For proof: run a simple sample script ignoring hint to erase the file; the script would
type
itself:Run above script observing hint to erase the file;
The batch file cannot be found
error shows that batch-parser cannot get nextecho
command:For the sake of completeness, here is a standard file system error message:
On the contrary, similar (for instance)
PowerShell
script is cached in memory. Again, run sample script ignoring hint to erase the file first; the script wouldtype
itself:Run the script observing hint to erase the file. Doing that would show that the latter
echo
andGet-Content
were cached in memory: