简体   繁体   English

如何将 Anaconda 管理员(提升的)命令控制台启动到 Windows 10 UserProfile 目录,而不是“c:\Windows\System32”

[英]How to launch Anaconda Administrator (elevated) Command Console into the Windows 10 UserProfile directory, NOT "c:\Windows\System32"

How do I launch Anaconda Administrator (elevated) Command Console into the Windows 10 UserProfile directory, NOT "c:\Windows\System32"?如何将 Anaconda 管理员(提升的)命令控制台启动到 Windows 10 UserProfile 目录,而不是“c:\Windows\System32”?

PROBLEM:问题:

I want to do this because it is a hassle to constantly have to change my working directory from "c:\Windows\System32" to "c:\users\mylogin" directory every time I start Anaconda Administrator Consoles.我想这样做是因为每次启动 Anaconda 管理员控制台时,都必须不断地将我的工作目录从“c:\Windows\System32”更改为“c:\users\mylogin”目录,这很麻烦。 The default Windows behavior is to ALWAYS launch administrator-privileged terminals in "c:\Windows\system32".默认的 Windows 行为是始终在“c:\Windows\system32”中启动具有管理员权限的终端。 This is a frequently used action as a Python programmer, sometimes executed multiple times per day, wasting my precious time.这是一个Python程序员经常用到的动作,有时一天要执行多次,浪费我宝贵的时间。

WHAT I TRIED:我试过什么:

I tried modifying my taskbar and Windows Start button shortcut for the Anaconda Administrator Prompt with the "Start In: = %USERPROFILE%" but that does nothing.我尝试使用“Start In: = %USERPROFILE%”修改任务栏和 Anaconda 管理员提示的 Windows 开始按钮快捷方式,但这没有任何作用。 It still launches the Admin console in c:\windows\system32.它仍然在 c:\windows\system32 中启动管理控制台。

I looked high and low for solutions.我四处寻找解决方案。 Someone suggested changing Windows Registry entry for CMD.exe, which is draconian and could screw up my Windows system when various other scripts run.有人建议将 Windows 注册表项更改为 CMD.exe,这太苛刻了,可能会在运行其他各种脚本时搞砸我的 Windows 系统。 This SO question suggests that, but also explains why the default Windows behavior does what's expected. This SO question 暗示了这一点,但也解释了为什么默认的 Windows 行为符合预期。

Does anyone have a good solution for this problem?有没有人有解决这个问题的好方法?

I found an ideal solution.我找到了一个理想的解决方案。

The normal Windows 10 shortcut for Anaconda runs the file "activate.bat" from the appropriate base environment's "Scripts" folder: Anaconda 的普通 Windows 10 快捷方式从适当的基本环境的“脚本”文件夹中运行文件“activate.bat”:

%windir%\System32\cmd.exe "/K" c:\ProgramData\Anaconda3\Scripts\activate.bat C:\ProgramData\Anaconda3

Modify the Anaconda file named "activate.bat" and add "cd %USERPROFILE% to the end of the "activate.bat" file. This activates the desired environment and then changes to the desired working directory. This has no other undesirable side effects on the Windows 10 operations.修改名为“activate.bat”的Anaconda文件,并在“activate.bat”文件的末尾添加“cd %USERPROFILE%”。这将激活所需的环境,然后切换到所需的工作目录。这没有其他不良副作用在 Windows 10 操作上。

The source code in "activate.bat" then looks as follows... “activate.bat”中的源代码如下所示......

@REM Copyright (C) 2012 Anaconda, Inc
@REM SPDX-License-Identifier: BSD-3-Clause
@REM Test first character and last character of %1 to see if first character is a "
@REM   but the last character isn't.
@REM This was a bug as described in https://github.com/ContinuumIO/menuinst/issues/60
@REM When Anaconda Prompt has the form
@REM   %windir%\system32\cmd.exe "/K" "C:\Users\builder\Miniconda3\Scripts\activate.bat" "C:\Users\builder\Miniconda3"
@REM Rather than the correct
@REM    %windir%\system32\cmd.exe /K ""C:\Users\builder\Miniconda3\Scripts\activate.bat" "C:\Users\builder\Miniconda3""
@REM this solution taken from https://stackoverflow.com/a/31359867
@set "_args1=%1"
@set _args1_first=%_args1:~0,1%
@set _args1_last=%_args1:~-1%
@set _args1_first=%_args1_first:"=+%
@set _args1_last=%_args1_last:"=+%
@set _args1=

@if "%_args1_first%"=="+" if NOT "%_args1_last%"=="+" (
    @CALL "%~dp0..\condabin\conda.bat" activate
    @GOTO :End
)

@REM This may work if there are spaces in anything in %*
@CALL "%~dp0..\condabin\conda.bat" activate %*

:End
@set _args1_first=
@set _args1_last=

@REM RICH ADDED THIS AS A CONVENIENCE to fix the Windows Shortcut for Anaconda Command Console so Console opens in %USERPROFILE%.
cd %USERPROFILE%

The only other thing required to make this totally work is to make sure that the CMD.exe for Anaconda runs as an "elevated" command console.使其完全工作所需的唯一另一件事是确保 Anaconda 的 CMD.exe 作为“高级”命令控制台运行。 (See picture) (见图)

将默认 CMD.exe 设置为以提升的管理员权限启动

You can launch it as admin by searching for it and then choosing open as admin.您可以通过搜索它然后选择以管理员身份打开来以管理员身份启动它。

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 dll与c:\\ windows \\ system32不同的目录 - dll in a different directory than c:\windows\system32 终端进程启动失败:shell 可执行文件“C:\Windows\System32”的路径不是符号链接文件 - The terminal process failed to launch: Path to shell executable "C:\Windows\System32" is not a file of a symlink 无法打开自我C:\\ Windows \\ system32 \\ file.exe或存档C:\\ Windows \\ system32 \\ file.pkg - Cannot open self C:\Windows\system32\file.exe or archive C:\Windows\system32\file.pkg 如何使用python在c:/windows/system32文件夹中创建文件 - How to create a file in c:/windows/system32 folder using python 作为 Windows 10 管理员,如何从 Python 以管理员身份运行命令? - As a Windows 10 administrator, how to run a command as administrator from Python? 在64位Windows上的C:\\ Windows \\ System32中的py2exe - py2exe in C:\Windows\System32 on 64-bit Windows Anaconda Navigator 无法启动(Windows 10) - Anaconda Navigator won't launch (windows 10) 权限被拒绝访问r“C:\\ Windows \\ System32 \\ Drivers \\ etc \\ hosts” - Permission denied to access r”C:\Windows\System32\Drivers\etc\hosts” 在 python 中执行 os.rmdir("C:\Windows\System32") 会发生什么? - What will happen on executing os.rmdir("C:\Windows\System32") in python? 权限错误 C:\WINDOWS\system32\config\systemprofile\.EasyOCR in IIS app which uses Python EXE - Permission Error C:\WINDOWS\system32\config\systemprofile\.EasyOCR in IIS app which uses Python EXE
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM