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

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

Join the Conversation


  1. Evil or not, this is the closest thing to PowerShell profile scripts that we have for cmd.exe. Your proposed solution seems quite useful.

    P.S.: You can also put a path to batch file in AutoRun. This is my cmd “profile.bat”:

    @echo off

    rem UTF-8 codepage
    chcp 65001 > NUL

    rem Fancy prompt (visual aid to clearly denote borders between multiple command outputs)
    prompt $E[0m$E[92;40m%USERNAME:$=$$%@%COMPUTERNAME%$E[97;40m$S$E[93;40m$P$E[97;40m$_§$S$E[39;49m

    rem Short alias for dotnet.exe
    doskey.exe dn=^"C:\Program Files\dotnet\dotnet.exe^" $*

    exit /b

Leave a comment

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: