- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将当前目录(从命令行)永久添加到 Windows 路径,但在实现此操作时遇到严重问题。
我最初的尝试是:
set PATH=%PATH%;%cd%
但是,这仅在当前 session 中有效;一旦我关闭命令行窗口,PATH
环境变量就会保留其以前的值。
接下来,我尝试了:
setx PATH=%PATH%;%cd%
根据我在此处找到的一些答案,这可能适用于 Windows 7 和 8,但在 Windows 10 中,setx
命令具有三种工作方式:
Syntax 1:
SETX [/S system [/U [domain\]user [/P [password]]]] var value [/M]
Syntax 2:
SETX [/S system [/U [domain\]user [/P [password]]]] var /K regpath [/M]
Syntax 3:
SETX [/S system [/U [domain\]user [/P [password]]]]
/F file {var {/A x,y | /R x,y string}[/M] | /X} [/D delimiters]
长话短说,我无法让它工作:
ERROR: Invalid syntax. Default option is not allowed more than '2' time(s).
如何以最简单的方式完成我的目标?
如果每个 Windows 版本都有不同的语法,那么我也很乐意获得此信息。
最佳答案
通过简单地使用覆盖或附加存储在注册表中的PATH
的文件夹路径来从批处理文件中修改系统或用户 PATH
是不好的本地 PATH
,如 Why are other folder paths also added to system PATH with SetX and not only the specified folder path? 的答案中详细描述
此任务的一种解决方案是将当前目录路径添加到用户 PATH
是使用以下代码:
@echo off
setlocal EnableExtensions DisableDelayedExpansion
for /F "skip=2 tokens=1,2*" %%G in ('%SystemRoot%\System32\reg.exe query "HKEY_CURRENT_USER\Environment" /v "Path" 2^>nul') do (
if /I "%%G" == "Path" (
set "UserPath=%%I"
if defined UserPath goto CheckPath
)
)
set "UseSetx=1"
if not "%CD:~1024,1%" == "" set "UseSetx="
if not exist %SystemRoot%\System32\setx.exe set "UseSetx="
if defined UseSetx (
%SystemRoot%\System32\setx.exe Path "%CD%" >nul
) else (
%SystemRoot%\System32\reg.exe ADD "HKCU\Environment" /f /v Path /t REG_SZ /d "%CD%" >nul
)
endlocal
exit /B
:CheckPath
setlocal EnableDelayedExpansion
if "!UserPath:~-1!" == ";" (set "Separator=") else "Separator=;"
set "PathCheck=!UserPath!%Separator%"
if not "!PathCheck:%CD%;=!" == "!PathCheck!" goto EndBatch
if not "!PathCheck:%CD%\;=!" == "!PathCheck!" goto EndBatch
set "PathToSet=!UserPath!%Separator%%CD%"
set "UseSetx=1"
if not "!PathToSet:~1024,1!" == "" set "UseSetx="
if not exist %SystemRoot%\System32\setx.exe set "UseSetx="
if defined UseSetx (
%SystemRoot%\System32\setx.exe Path "!PathToSet!" >nul
) else (
set "ValueType=REG_EXPAND_SZ"
if "!PathToSet:%%=!" == "!PathToSet!" set "ValueType=REG_SZ"
%SystemRoot%\System32\reg.exe ADD "HKCU\Environment" /f /v Path /t !ValueType! /d "!PathToSet!" >nul
)
:EndBatch
endlocal
endlocal
此解决方案的缺点是用户 PATH
最终成为 C:\Temp;C:\Temp\Other Folder;C:\Temp\One More Folder
(当当前目录是第一个 C:\Temp
时,在下次运行批处理文件时 C:\Temp\Other Folder
和 C:\Temp\One More Folder
在第三次执行批处理文件时。
避免这种情况的解决方案是在下一个批处理文件 MyAppPath
中定义一个特定于应用程序的环境变量,该变量在执行批处理文件时始终会被覆盖。如果 user PATH
中尚不存在对环境变量 MyAppPath
的引用,则仅向 user PATH
添加对环境变量 PATH
的引用。
@echo off
setlocal EnableExtensions DisableDelayedExpansion
set "UseSetx=1"
if not "%CD:~1024,1%" == "" set "UseSetx="
if not exist %SystemRoot%\System32\setx.exe set "UseSetx="
if defined UseSetx (
%SystemRoot%\System32\setx.exe MyAppPath "%CD%" >nul
) else (
%SystemRoot%\System32\reg.exe ADD "HKCU\Environment" /f /v MyAppPath /t REG_SZ /d "%CD%" >nul
)
set "UserPath="
for /F "skip=2 tokens=1,2*" %%G in ('%SystemRoot%\System32\reg.exe query "HKEY_CURRENT_USER\Environment" /v "Path" 2^>nul') do (
if /I "%%G" == "Path" (
set "UserPath=%%I"
if defined UserPath goto CheckPath
)
)
if exist %SystemRoot%\System32\setx.exe (
%SystemRoot%\System32\setx.exe Path "%%MyAppPath%%" >nul
) else (
%SystemRoot%\System32\reg.exe ADD "HKCU\Environment" /f /v Path /t REG_EXPAND_SZ /d "%%MyAppPath%%" >nul
)
endlocal
exit /B
:CheckPath
setlocal EnableDelayedExpansion
if "!UserPath:~-1!" == ";" (set "Separator=") else set "Separator=;"
if "!UserPath:%%MyAppPath%%=!" == "!UserPath!" (
set "PathToSet=!UserPath!%Separator%%%MyAppPath%%"
set "UseSetx=1"
if not "!PathToSet:~1024,1!" == "" set "UseSetx="
if not exist %SystemRoot%\System32\setx.exe set "UseSetx="
if defined UseSetx (
%SystemRoot%\System32\setx.exe Path "!PathToSet!" >nul
) else (
%SystemRoot%\System32\reg.exe ADD "HKCU\Environment" /f /v Path /t REG_EXPAND_SZ /d "!PathToSet!" >nul
)
)
endlocal
endlocal
在这种情况下,存储在注册表中的用户 %MyAppPath%
始终仅包含 MyAppPath
,并且注册表值的类型为 REG_EXPAND_SZ。环境变量 MyAppPath
的值也存储在注册表中,但类型为 REG_SZ。 PATH
的值在每次执行批处理文件时更新为当前目录路径。因此,每次从不同文件夹执行批处理文件时,注册表中的用户 PATH
不会变得越来越长。
一般来说,如果应用程序或应用程序套件的应用程序文件夹或其子文件夹之一在执行应用程序或套件中的任何应用程序时必须位于本地 App Paths
中才能正常工作,则该应用程序或应用程序套件的编码不好全部。应用程序或应用程序套件还可以将其安装路径存储在注册表中的其他位置,例如 %APPDATA%
或 PATH
子文件夹中的文件(用户帐户相关的标准应用程序数据路径),下次运行时可以从中读取它。仅当此应用程序很可能主要由用户在命令提示符窗口中执行时,安装程序包才应修改用户或系统 echo /?
。
要了解所使用的命令及其工作原理,请打开 command prompt 窗口,在其中执行以下命令,并完整、仔细地阅读每个命令显示的帮助页面。
endlocal /?
exit /?
for /?
goto /?
if /?
reg /?
reg add /?
reg query /?
set /?
setlocal /?
setx /?
>nul
还应阅读以下内容:
App Paths
。PATH
的详细信息。关于batch-file - 将当前目录永久添加到 Windows 路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47070156/
我试图通过这段代码读取未知数量的整数: while (1) { int c = getchar (); if (c == EOF) break;
我正试图找到一个类似于谷歌分析日期选择器的日期选择器: 知道 jQuery 是否提供了类似的东西吗? 最佳答案 这个 Twitter Bootstrap 风格的日期范围选择器非常接近。 https:/
我正在使用 javascript。如何获取当前 URL 的路径并将其分配给我的代码?这是我的代码: $(document).ready(function() { $(".share").hides
如何获得今天的Julian day number (JDN)相等的?或任何日期? 我看了又看,但只发现了一些产生“year-dayOfYear”的函数,而不是:2457854。 最佳答案 在 bash
我有相当简单的 UDP 服务器写在 c 上。 有时我需要知道在套接字中排队的所有 udp 数据包(字节)的当前长度。 据我了解,getsockopt 没有得到这样的信息。 欢迎使用 Linux 和 F
我一直在寻找几个小时来找到一个可以在图像中添加诸如“填充:5px”之类的东西的插件。每个人都通过纯 html 做到这一点吗?我们的客户需要一种方法来简单地使用按钮或右键单击上下文菜单来添加它。有什么建
是否有可能获得当前正在执行的 TCL 脚本的完整路径? 在 PHP 中,它将是:__FILE__ 最佳答案 根据“当前正在执行的 TCL 脚本”的含义,您实际上可能会寻找 info script ,甚
我最近从直接使用 ISession 转向了包装的 ISession,即工作单元类型模式。 我曾经使用 SQL Lite(内存中)对此进行测试。我有一个简单的帮助器类,它配置我的 SessionFact
我按照步骤操作 here在 WebStorm 中配置代码完成和其他内容,但我仍然收到以下语法错误。 我该如何解决这个问题? 最佳答案 通过相应地将“JavaScript 语言版本”(Settings/
我可以为我团队的 TFS 当前 Sprint 任务板添加书签吗?我们有两周的冲刺,因此 URL 每两周更改一次。 默认 URL 的形式为: http://[Server]/tfs/[Project]/
是否有 Subversion 命令可以显示当前版本号? 在svn checkout之后,我想启动一个脚本并需要变量中的修订号。如果有像 svn info get_revision_number 这样的
我正在编写表单的一个组件 首次安装组件时,sources={{}} ,一本空字典。由于该组件包装了现有的 Javascript 库,因此我正在实现一个自定义比较函数。为了让这个 diffing 函数
无论系统时间设置为多少以及机器所在的时区,我都需要正确的 UTC 时间。 (即使我必须打电话到互联网才能同步......) 是否有一些库或其他方法可以优雅地做到这一点? 最佳答案 如果您想获得准确可靠
我一边编码,一边拿出一些我和 friend 建立的旧网站来重新开始工作。我已经有一段时间没有做过任何 AJAX 了,当我试图找出我的代码失败的地方时,我发现没有显示很多资源。我猜这是因为我使用的是旧方
由于对性能的巨大影响,我从不怀疑我现在的桌面CPU是否有分支预测。当然可以。但各种 ARM 产品又如何呢? iPhone或Android手机有分支预测吗?较旧的任天堂 DS?基于 PowerPC 的
我有一个具有以下有效负载的 JWT: { "id": "394a71988caa6cc30601e43f5b6569d52cd7f6df", "jti": "394a71988caa6cc30
从其他一些帖子中,我能够通过以下方式获取当前 URI: 但是以下方法不起作用: 我很好奇为什么上面的方法不起作用,以及如何将当前 URI 分配给字符串。 最佳答案 每the javadocs ,g
我在表格 View 中有几个单元格。现在在任何给定的时间点,我想计算 View 中单元格的当前高度,即如果它是 View 的 3/4,它应该返回 (cellheight)*3/4 高度。 我通过以下方
这是网站的身份验证脚本。这安全吗?是最近的节目吗?它已经过时了吗?是否有“更好更安全的方法”我很新,但我没有看到太多地方使用 header 授权。 如有任何帮助,我们将不胜感激!这是我制作的第一个登录
我已经在其他 stackoverflow 线程上检查过这个错误,但在我的代码中没有发现任何错误。也许我累了,但我觉得还好。 网站.urls.py: from django.conf.urls impo
我是一名优秀的程序员,十分优秀!