67

Problem description

I got this problem in my Win10 Pro Machine. I uninstalled Anaconda because it gaves me problem with Jupyter notebook and reinstalled it. But since then I'm unable to access Command Prompt.

As soon as I open it it closes. I figure it out opening VSCode and reading Cmd has exited with error code 1. And now nor Anaconda Prompt is starting up, but as soon as I open PowerShell it's says (conda) so I think it works from there.

powershell and cmd /d

From Powershell if i type in cmd and it exit immediately without complaining about anything. But if I type cmd /d it works.

Tried fix that didn't work

  • Removing Anaconda from path
  • I read somewhere here that it may be caused by some kind of bad command on cmd startup and in fact with cmd /d works as usual.
  • I tried to follow the registry fix about startup commands for cmd but the registry entry was missing in my case maybe this could be the issue
  • Neither sfc /scannow nor DISM.exe /Online /Cleanup-image /Scanhealth worked

Infomation i found online

According to this website ErrorCode 1 'Indicates that Action has attempted to execute non-recognized command in Windows command prompt cmd.exe'.

Actual request

Can anyone help me with this issue please? I tried to look online for a week but with no luck, thank you for your time

Filippo Vicari
  • 773
  • 1
  • 5
  • 6
  • 6
    @Mofi Thank you very much man! `C:\Windows\System32\reg.exe DELETE "HKCU\Software\Microsoft\Command Processor" /v AutoRun /f` actually worked but I cannot mark your answer as correct because it's a comment. If you want to copy paste it as the answer I will mark it as complete – Filippo Vicari Feb 25 '21 at 08:55
  • Thank you again for everything! Super appreciated I will surely do as you said, thanks again – Filippo Vicari Feb 25 '21 at 11:52
  • Thank you, had exactly the same issue, but to me it happened uninstalling-reinstalling Miniforge. I have been banging my head for several hours before finiding your post. Too bad the comment from @Mofi is deleted and was never posted as an answer; I would have liked to understand the "why" and "how". – F. Remonato Jun 10 '21 at 15:28

7 Answers7

180

The following answer was (supposedly) initially posted (but later removed) by @Mofi and I got it from the comment of @filippo-vicari. So all credits go to them, thanks for solving this issue! It took me hours to finally find their solution.

Enter the following command into the still working powershell (in my case Anaconda Powershell):

C:\Windows\System32\reg.exe DELETE "HKCU\Software\Microsoft\Command Processor" /v AutoRun /f

It worked for me immediately. cmd.exe and Anaconda Prompt now work flawlessly again!

crisprog
  • 2,024
  • 1
  • 8
  • 14
  • I think the "AutoRun" key is added to the registry after running `conda init`. – blaylockbk Oct 04 '21 at 21:09
  • 1
    Just leaving a comment here, because I got to this from another issue where npm would not work (just din't output anything or do anything), turns out it was because of this cmd crash preventing it to work correctly. So If anyone has the same issue with npm, try it out! – Erdorath Mar 24 '23 at 14:17
  • Per the `cmd.exe` documentation: " If /D was NOT specified on the command line, then when CMD.EXE starts, it looks for the following REG_SZ/REG_EXPAND_SZ registry variables, and if either or both are present, they are executed first. HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun and/or HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun Command Extensions are enabled by default. " My HKLM registry value also had an empty "if exists " statement which was necessary to reset to an empty string. – PetMetz Apr 17 '23 at 16:27
  • 1
    One additional note here, if you are in a corp environment where you need admin to run `regedit` and go looking for the key under HKCU then bear in mind this will not be the hive for your regular user. This cost me a fair bit of time before I realised I just needed to search under `HKEY_USERS` instead. Also if you have uninstalled/reinstalled Anaconda you'll want to fix the value rather than deleting it, the correct val should be something like `if exist "C:\Anaconda3\condabin\conda_hook.bat" "C:\Anaconda3\condabin\conda_hook.bat"` – Mike Nunan May 16 '23 at 11:44
  • 1
    @MikeNunan I believe you can also just delete the registry value and then run `conda init` from the Anaconda prompt to restore the correct value. This has the small advantage that it should automatically use whatever folder Anaconda is installed in -- which may be something other than "C:\Anaconda3". – Tim Goodman Jun 20 '23 at 15:59
  • Thank you so much! I was so frustrated with this issue. It worked immediately with your solution! – Shariq farooq Jun 22 '23 at 16:56
23

I had the same problem after completely uninstalling anaconda (without reinstalling it). I was able to fix it by going to "Computer\HKEY_CURRENT_USER\Software\Microsoft\Command Processor" in the registry editor and deleting the AutoRun key.

Dharman
  • 30,962
  • 25
  • 85
  • 135
CamelCaseCam
  • 231
  • 2
  • 2
1

If somebody (like me) still having problems like 'Code: 1' and shell says 'cmd.exe is not a command', just add C:\Windows\system32 to the PATH

  • The first directory path in __system__ environment variable `Path` is by Windows default `%SystemRoot%\System32`. If the __system__ `Path` does not contain anymore this directory path exactly as written here with referencing the value of the environment variable `SystemRoot`, then it can be expected that the __system__ and __user__ environment variables `Path` must be manually reconstructed by the user according to the already installed applications and the used Windows version. – Mofi Jun 07 '22 at 07:10
1

Comment by Mike Nunan was key for me. Adding as an Answer to make it obvious to other people, who may miss Mike's comment.

If you are in a corporate environment, the AutoRun of the active user will likely NOT be in HKCU\Software\Microsoft\Command Processor but in HKEY_USERS.

My Error: command prompt opens and closes immediately following improper anaconda uninstall (uninstall throwed errors)

Diagnostic: press WIN+R, type ‘cmd’. This should abnormally open and close immediately. if ‘cmd /d’ opens normally, then fix I used is below.

Fix: With admin privilege in Registry Editor, search (CTRL+F) for ‘Command Processor’ keys. In HKEY_USERS, something like HKEY_USERS/**RANDOM NUMBERS**/SOFTWARE/Microsoft/Command Processor will show up, delete ‘AutoRun’ entry. Repeat for all Command Processor keys associated to all different users (the random numbers). Restart computer to take registry modification in effect. As per Mike Nunan's comment, you can also edit the values rather than deleting the AutoRun if you still have Anaconda installed - just make sure to know where your Anaconda is installed. For instance: the data of the Autorun value with string type could be if exist "C:\Anaconda3\condabin\conda_hook.bat" or if exist "C:\ProgramData\anaconda3\condabin\conda_hook.bat" etc. Check your install!

0

This answer solved it for me.

Open the registry key Computer\HKEY_CURRENT_USER\Software\Microsoft\Command Processor and delete the value AutoRun.

The AutoRun value would probably run a custom command or script related to Anaconda. Because Anaconda was already uninstalled, the script doesn't exist anymore and fails while crashing the CMD.


I am just leaving this answer with some additional hints, phrases, and error messages (for SEO) so that others can find this answer via Google:

I hade the exact same problem as the question asker and noticed it first because npm was not working anymore after uninstalling Anaconda. Typing node -v in PowerShell answered the node version, but npm -v didn't print anything (also no error).

I reinstalled node.js and the PATH variable was configured correctly. But opening a Powershell window in the directory C:\Program Files\nodejs and running .\npm.cmd -v or .\npm -v didn't print anything (also no error).

PS C:\Program Files\nodejs> .\npm.cmd -v
PS C:\Program Files\nodejs>

It was still possible for me to run bash scripts directly via a git bash installation:

& "C:\Program Files\Git\bin\bash.exe" .\hello.sh
Hello World

Running cmd in a Powershell window did only print the Windows version without switching the window to a CMD prompt:

PS C:\Users\USERNAME> cmd
Microsoft Windows [Version 10.0.19045.3208]
(c) Microsoft Corporation. All rights reserved.
PS C:\Users\USERNAME>

When opening CMD in the VS Code terminal I got this error:

The terminal process "C:\Windows\System32\cmd.exe" terminated with exit code: 1.

Starting a new CMD prompt in Windows Terminal gave this error:

[process exited with code 1]
Tobi Obeck
  • 1,918
  • 1
  • 19
  • 31
  • The Windows Terminal error was actually in German to be more precise: [Verarbeitung des Prozesses mit Code 1 (0x00000001) beendet] Sie können dieses Terminal jetzt mit STRG+D schließen oder zum Neustart die EINGABETASTE drücken. – Tobi Obeck Jul 28 '23 at 09:38
-2

Not only a location af HKCU. These should be deleted too:

HKLM\Software\Microsoft\Command Processor
  • The entire registry key `HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor` should __not__ be deleted, only the registry value `AutoRun` on existing under this key at all which is usually not the case as adding the registry value `AutoRun` under this key requires the elevated privileges of a local administrator as also its deletion with `%SystemRoot%\System32\reg.exe DELETE "HKLM\Software\Microsoft\Command Processor" /v AutoRun /f`. – Mofi Jun 07 '22 at 07:06
-2

Add the following value to the system variable Path:

 C:\Windows\system32 
ouflak
  • 2,458
  • 10
  • 44
  • 49
  • The first directory path in __system__ environment variable `Path` is by Windows default `%SystemRoot%\System32`. If the __system__ `Path` does not contain anymore this directory path exactly as written here with referencing the value of the environment variable `SystemRoot`, then it can be expected that the __system__ and __user__ environment variables `Path` must be manually reconstructed by the user according to the already installed applications and the used Windows version. – Mofi Jun 07 '22 at 07:09