CMD crashes (process exited with code 1) / VSCode remote SSH fails

CMD闪退(process exited with code 1)

Usually, the problem of CMD flashback (process exited with code 1) is caused by uninstalling Conda. When installing Conda on Windows, conda init may modify or create the "AutoRun" value of the command processor registry key to set environment variables or automatically execute commands when the command prompt starts. If you do not restore the default command prompt settings after uninstalling Conda, it may cause the command prompt to crash and cause VSCode's remote SSH to fail.

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.

One of the ways to solve this problem is to conda init cmd.exeinitialize the conda environment of cmd by running the command, overwrite the original AutoRun settings or modify the original AutoRun. Another way is to use the command C:\Windows\System32\reg.exe DELETE "HKCU\Software\Microsoft\Command Processor" /v AutoRun /f·AQS356RESto delete AutoRun information. This will delete the AutoRun key value under the specified registry key path, thereby resolving issues related to it.
View the content of the function that initializes the cmd.exe registry as follows:

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

Specifically, it reads the "AutoRun" key in the Windows registry, then creates a new hook with the specified conda path, and adds it to "AutoRun". If the reverse parameter is set to True, the function will remove the hook from "AutoRun". Before updating "AutoRun", the function will also do some other processing, such as merging duplicate hooks into one, and merging new hooks with existing hooks, thus fixing the CMD crash problem. If the "AutoRun" key is successfully updated, the function returns Result.MODIFIED; otherwise, the function returns Result.NO_CHANGE.

reference

https://github.com/conda/constructor/pull/521

Guess you like

Origin blog.csdn.net/bigbaojian/article/details/129760574