shell:startup 打开的 echo 目录
Echo directory opened by shell:startup
当在命令提示符中输入 start shell:startup
时,它会在启动文件夹中打开一个新的 window。如何打印该文件夹的路径但实际上不在资源管理器中打开该文件夹?
您可以使用 .NET's Environment.SpecialFolder
。此 PowerShell 命令将为您提供启动文件夹的路径
[Environment]::GetFolderPath([Environment+SpecialFolder]::Startup)
如果你真的想使用 cmd 就这样调用它
powershell -Com "[Environment]::GetFolderPath([Environment+SpecialFolder]::Startup)"
并使用 for /f
将其保存到像 normal
一样的变量中
无需借助 PowerShell 即可使用纯批处理获取路径,但要复杂得多
注册表中有 2 个键包含特殊文件夹的路径:HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
和 HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
。这是从 :
中解析它们的方法
@echo off
setlocal EnableExtensions DisableDelayedExpansion
set "StartupFolder="
for /F "skip=1 tokens=1,2*" %%I in ('%SystemRoot%\System32\reg.exe QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v Startup 2^>nul') do if /I "%%I" == "Startup" if not "%%~K" == "" if "%%J" == "REG_SZ" (set "StartupFolder=%%~K") else if "%%J" == "REG_EXPAND_SZ" call set "StartupFolder=%%~K"
if not defined StartupFolder for /F "skip=1 tokens=1,2*" %%I in ('%SystemRoot%\System32\reg.exe QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v Startup 2^>nul') do if /I "%%I" == "Startup" if not "%%~K" == "" if "%%J" == "REG_SZ" (set "StartupFolder=%%~K") else if "%%J" == "REG_EXPAND_SZ" call set "StartupFolder=%%~K"
if not defined StartupFolder set "StartupFolder=\"
if "%StartupFolder:~-1%" == "\" set "StartupFolder=%StartupFolder:~0,-1%"
if not defined StartupFolder set "StartupFolder=%UserProfile%\Startup"
echo Startup folder is: "%StartupFolder%"
endlocal
当在命令提示符中输入 start shell:startup
时,它会在启动文件夹中打开一个新的 window。如何打印该文件夹的路径但实际上不在资源管理器中打开该文件夹?
您可以使用 .NET's Environment.SpecialFolder
。此 PowerShell 命令将为您提供启动文件夹的路径
[Environment]::GetFolderPath([Environment+SpecialFolder]::Startup)
如果你真的想使用 cmd 就这样调用它
powershell -Com "[Environment]::GetFolderPath([Environment+SpecialFolder]::Startup)"
并使用 for /f
将其保存到像 normal
无需借助 PowerShell 即可使用纯批处理获取路径,但要复杂得多
注册表中有 2 个键包含特殊文件夹的路径:HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
和 HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
。这是从
@echo off
setlocal EnableExtensions DisableDelayedExpansion
set "StartupFolder="
for /F "skip=1 tokens=1,2*" %%I in ('%SystemRoot%\System32\reg.exe QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v Startup 2^>nul') do if /I "%%I" == "Startup" if not "%%~K" == "" if "%%J" == "REG_SZ" (set "StartupFolder=%%~K") else if "%%J" == "REG_EXPAND_SZ" call set "StartupFolder=%%~K"
if not defined StartupFolder for /F "skip=1 tokens=1,2*" %%I in ('%SystemRoot%\System32\reg.exe QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v Startup 2^>nul') do if /I "%%I" == "Startup" if not "%%~K" == "" if "%%J" == "REG_SZ" (set "StartupFolder=%%~K") else if "%%J" == "REG_EXPAND_SZ" call set "StartupFolder=%%~K"
if not defined StartupFolder set "StartupFolder=\"
if "%StartupFolder:~-1%" == "\" set "StartupFolder=%StartupFolder:~0,-1%"
if not defined StartupFolder set "StartupFolder=%UserProfile%\Startup"
echo Startup folder is: "%StartupFolder%"
endlocal