CMD闪退(process exited with code 1)
通常,CMD闪退(process exited with code 1)这个问题是由卸载Conda引起的。在Windows上安装Conda时,conda init可能会修改或创建命令处理器注册表键的“AutoRun”值,以设置环境变量或在命令提示符启动时自动执行命令。如果在卸载Conda后没有恢复默认的命令提示符设置,可能会导致命令提示符闪退,进而导致VSCode的远程SSH失败。
Because of that oversight, when a Windows user who has run conda init after conda/conda@b4f3210 attempts to uninstall Anaconda using Uninstall-Anaconda3.exe, the conda hook isn’t deleted properly from the registry by the constructor
/nsis/_nsis.py
script, which breaks CMD.exe and causes system instability.
解决这个问题的方法之一是通过运行conda init cmd.exe
命令初始化cmd的conda环境,覆盖原有的AutoRun设置或修改原有的AutoRun。另一种方法是使用命令C:\Windows\System32\reg.exe DELETE "HKCU\Software\Microsoft\Command Processor" /v AutoRun /f·AQS356RES
删除AutoRun信息。这将删除指定注册表键路径下的AutoRun键值,进而解决与其相关的问题。
查看初始化cmd.exe注册表的函数的内容如下:
def init_cmd_exe_registry(target_path, conda_prefix, reverse=False):
# HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun
# HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun
prev_value, value_type = _read_windows_registry(target_path)
if prev_value is None:
prev_value = ""
value_type = winreg.REG_EXPAND_SZ
old_hook_path = '"{}"'.format(join(conda_prefix, 'condabin', 'conda_hook.bat'))
new_hook = 'if exist {hp} {hp}'.format(hp=old_hook_path)
if reverse:
# we can't just reset it to None and remove it, because there may be other contents here.
# We need to strip out our part, and if there's nothing left, remove the key.
# Break up string by parts joined with "&"
autorun_parts = prev_value.split('&')
autorun_parts = [part.strip() for part in autorun_parts if new_hook not in part]
# We must remove the old hook path too if it is there
autorun_parts = [part.strip() for part in autorun_parts if old_hook_path not in part]
new_value = " & ".join(autorun_parts)
else:
replace_str = "__CONDA_REPLACE_ME_123__"
# Replace new (if exist checked) hook
new_value = re.sub(
r'(if exist \"[^\"]*?conda[-_]hook\.bat\" \"[^\"]*?conda[-_]hook\.bat\")',
replace_str,
prev_value,
count=1,
flags=re.IGNORECASE | re.UNICODE,
)
# Replace old hook
new_value = re.sub(
r'(\"[^\"]*?conda[-_]hook\.bat\")',
replace_str,
new_value,
flags=re.IGNORECASE | re.UNICODE,
)
# Fold repeats of 'HOOK & HOOK'
new_value_2 = new_value.replace(replace_str + ' & ' + replace_str, replace_str)
while new_value_2 != new_value:
new_value = new_value_2
new_value_2 = new_value.replace(replace_str + ' & ' + replace_str, replace_str)
new_value = new_value_2.replace(replace_str, new_hook)
if new_hook not in new_value:
if new_value:
new_value += ' & ' + new_hook
else:
new_value = new_hook
if prev_value != new_value:
if context.verbosity:
print('\n')
print(target_path)
print(make_diff(prev_value, new_value))
if not context.dry_run:
_write_windows_registry(target_path, new_value, value_type)
return Result.MODIFIED
else:
return Result.NO_CHANGE
具体而言,它会读取Windows注册表中的"AutoRun"键值,然后使用指定的conda路径创建一个新的hook,并将其添加到"AutoRun"中。如果reverse参数设置为True,则函数会将hook从"AutoRun"中删除。在更新"AutoRun"之前,函数还会进行一些其他处理,例如将重复的hook合并为一个,以及将新的hook与现有的hook合并,从而修复了CMD闪退问题。如果成功更新了"AutoRun"键值,则函数返回Result.MODIFIED;否则,函数返回Result.NO_CHANGE。