Can't run batch files by doubleclicking but they run fine when typed in cmd window or WinKEY+R

2

Okay this is weird. I'm at a loss as to why this is happening or how to fix this. The title pretty much says it all but i will elaborate further:

Opening cmd.exe to run commands or call batch files: OK
Opening WinKEY+R to run batch files: OK
Opening batch files by doubleclicking: ...is not recognized as an internal or external command, operable program or batch file.

This error is not limited to specific commands im calling via batch files. Even the simplest commands seem to fail.

So my first guess was that something is wrong with file associations or environment variables. Checked those but they seem fine:

ComSpec is %SystemRoot%\system32\cmd.exe
PATHEXT is .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
PATH is C:\Windows\System32\;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;

Registry looks ok too:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.cmd

OpenWithList subkey is empty. OpenWithProgids contains:

(Default) REG_SZ (value not set)  

cmdfile REG_NONE (zero-leght binary value)

It's a fairly new windows install. Windows 7 x64. Any ideas where to look now?

TMRW

Posted 2017-05-02T15:01:55.930

Reputation: 974

Answers

1

Ok i think i figured it out. Apparently before i posted i was missing C:\Windows\System32\ from PATH variable. Adding this and making the post did not change anything until i did the oldest fix in the book: a restart. That fixed it. Also for some reason (not sure this is default) the USERNAME variable was SYSTEM not my username. Putting %username% to cmd returned my username correctly. Bit odd but everything seems to be working now.

TMRW

Posted 2017-05-02T15:01:55.930

Reputation: 974

1

This sounds like an encoding issue. Unless you know you need UTF-8 or Unicode, try saving a copy of your batch file encoded in ANSI.

  1. Open batch file in Notepad
  2. File (menu), Save As
  3. Type a different filename (to not overwrite)
  4. Select ANSI in the Encoding dropdown
  5. Click Save

Note: If your batch file requires UTF-8 or Unicode characters, the process is more complicated.

Steven

Posted 2017-05-02T15:01:55.930

Reputation: 24 804