Python 仅适用于管理员



我关注了这个视频:https://www.youtube.com/watch?v=Y2q_b4ugPWk并让我的CMD将Python识别为路径变量。 但这只有在我以管理员身份打开 cmd 和 powershell 时才有效。 如何让它适用于所有用户?

作为管理员:

PS C:windowssystem32> python
Python 3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 10:22:32) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

作为用户:

PS C:Users> python
python : The term 'python' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ python
+ ~~~~~~
    + CategoryInfo          : ObjectNotFound: (python:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
PS C:Users>

具有提升的权限(右键单击powershell.exe,以管理员身份运行(

$PathToPython = 'C:whatevercontainingfolderforpythonexe'
$CurrentValue = [Environment]::GetEnvironmentVariable('Path', 'Machine')
[Environment]::SetEnvironmentVariable('Path', "$CurrentValue;$PathToPython", 'Machine')

我为我的powershell脚本构建了一个批处理打开器。以提升的权限打开后,调用的任何其他脚本也会提升。我用 .vbs 做了类似的事情来在管理员中打开批处理。

@ECHO off
ECHO Please Wait.
powershell.exe -ExecutionPolicy ByPass -file "File.ps1"
ECHO.
ECHO PRESS ANY KEY ONCE DEBUGGED
Pause >nul
exit

相关内容

  • 没有找到相关文章

最新更新