Skip to content
mnaoumov.dev
Go back

cmd.exe AutoRun feature = evil feature

Hi folks

Today I was debugging some issues for hours. Some command-line tools from Node.JS, or C++ compiler just complained with weird errors such as File does not exist when the file clearly existed. I was pulling my hair off and then eventually I found it!

cmd.exe has an AutoRun feature. You can add some command to HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun or HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun which will be executed any time

I found that I put the following script in that AutoRun setting chcp 65001 . I was trying to do that to fix Unicode characters output in the console. It did not work but I forgot to remove that AutoRun script.

The problem with that script, is that it outputs extra line Active code page: 65001 on every cmd.exe start

Because of that extra lines, all the scripts that rely on parsing scripts output might fail in a weird way.

For example, one of the issues I was encountering https://github.com/desktop/desktop/issues/8454

So if you need to add some script to AutoRun you have to ensure it doesn’t produce any output.

I would think about something like mycoolcommand 1>NUL 2>NUL & SET ERRORLEVEL=0

So this will ensure we did not put anything in stdout, stderr and did not return any bad exit codes

Stay tuned


Share this post on:

Previous Post
Windows case-insensitive file names = nightmares with Node.JS
Next Post
Post SQL output to bug tracker details - Mr. Data Converter