I ran into this issue this past weekend while doing some planned work. I wrote some very simple bat files that had a lot of repetitive tasks in them that I simply did not want to manually type out. (I generated them with PowerShell, but that’s a different topic). When it was time to run these I proudly double-clicked the bat files thinking “gee whiz I sure am efficient” and of course nothing happened. Well not exactly. A window would briefly pop open on the screen and immediately close. What’s going on? Just to make sure I wasn’t crazy, I wrote a very simple test bat file.
echo %username% pause
Same problem. I made sure I was running with proper credentials as well, but no luck. So I tried running the bat file via the command line and saw it report an error:
'■e' is not recognized as an internal or external command, operable program or batch file.
This threw me for a loop. What’s this mystery character it’s not recognizing? If I run the same command for echo %username% in the command line it works fine so it’s not that. I reviewed the file in Notepad++ and was sure to enable the “Show all Characters” option under the view menu just to make sure there weren’t any weird characters. I didn’t see anything here either.
So what fixed it? Turns out Notepad was defaulting to Unicode instead of ANSI for the encoding type. When you go to “Save As” you’ll see a drop down menu next to the Save button that says Encoding. Change this to ANSI. This got everything working for me. Such a simple thing to overlook. Hopefully someone finds this helpful.