作为外观输出而捕获的windir未被解析为环境变量

时间:2016-02-29 23:30:23

标签: windows batch-file cmd

我从注册表中获取InetSrv文件夹的路径并持久保存在本地变量中。 现在,当对该已保存变量尝试更改目录命令(CD)时,则抛出错误。

@echo off
SETLOCAL
set vb_path=""
for /f "tokens=1-2*" %%A in ('REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\InetStp" /v InstallPath') do (set vb_path=%%C)
echo %vb_path%
cd %vb_path%
ENDLOCAL

输出

 %windir%\system32\inetsrv
The system cannot find the path specified.

1 个答案:

答案 0 :(得分:1)

使用CALL set "vb_path=%%C"

这会扩展%windir%

%windir%\system32\inetsrv部分
@echo off
SETLOCAL EnableExtensions
set "vb_path="
for /f "tokens=1-2*" %%A in ('
        REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\InetStp" /v InstallPath
    ') do (CALL set "vb_path=%%C")
echo %vb_path%
cd %vb_path%
ENDLOCAL