我想通过CMD在Windows 10中找到自动运行文件夹的位置。我试过
dir /AD Startup
但我得到了以下错误:
Volume in drive C has no label.
Volume Serial Number is $here_is_the_serial_number
File Not Found
我知道还有其他方法可以找到自动运行文件夹,但我需要通过CMD找到它。
有人知道我怎么能找到它吗?
Nvm。我明白了。如果你们有同样的问题,下面的命令对我有效:
dir Startup /s
无需在驱动器的所有目录中搜索名为Startup
的文件夹。
自WindowsVista:以来,默认情况下有
%ALLUSERSPROFILE%MicrosoftWindowsStart MenuProgramsStartup
这是所有用户在"开始"菜单中的常用启动文件夹%APPDATA%MicrosoftWindowsStart MenuProgramsStartup
这是当前用户启动菜单中的启动文件夹
获取当前用户真正使用的启动文件夹的批处理文件是:
@echo off
setlocal EnableExtensions DisableDelayedExpansion
set "StartupFolder="
for /F "skip=1 tokens=1,2*" %%I in ('%SystemRoot%System32reg.exe QUERY "HKCUSoftwareMicrosoftWindowsCurrentVersionExplorerUser 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%System32reg.exe QUERY "HKCUSoftwareMicrosoftWindowsCurrentVersionExplorerShell 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 "%APPDATA%MicrosoftWindowsStart MenuProgramsStartup"
echo Startup folder of current user is:
echo "%StartupFolder%"
endlocal
有关此代码的完整解释,请使用与获取当前用户的真实Desktop文件夹相同的批处理文件代码阅读此答案。我刚刚用Startup
替换了所有出现的Desktop
,以更改Startupshell文件夹的代码。
为所有用户获得真正使用的通用启动文件夹的批处理文件是:
@echo off
setlocal EnableExtensions DisableDelayedExpansion
set "StartupFolder="
for /F "skip=1 tokens=2,3*" %%I in ('%SystemRoot%System32reg.exe QUERY "HKLMSoftwareMicrosoftWindowsCurrentVersionExplorerUser Shell Folders" /v "Common 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=2,3*" %%I in ('%SystemRoot%System32reg.exe QUERY "HKLMSoftwareMicrosoftWindowsCurrentVersionExplorerShell Folders" /v "Common 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=%ALLUSERSPROFILE%MicrosoftWindowsStart MenuProgramsStartup"
echo Common startup folder for all users is:
echo "%StartupFolder%"
endlocal
两个FOR命令行也可以是:
for /F "skip=1 tokens=1-3*" %%I in ('%SystemRoot%System32reg.exe QUERY "HKLMSoftwareMicrosoftWindowsCurrentVersionExplorerUser Shell Folders" /v "Common Startup" 2^>nul') do if /I "%%I %%J" == "Common Startup" if not "%%~L" == "" if "%%K" == "REG_SZ" (set "StartupFolder=%%~L") else if "%%K" == "REG_EXPAND_SZ" call set "StartupFolder=%%~L"
if not defined StartupFolder for /F "skip=1 tokens=1-3*" %%I in ('%SystemRoot%System32reg.exe QUERY "HKLMSoftwareMicrosoftWindowsCurrentVersionExplorerShell Folders" /v "Common Startup" 2^>nul') do if /I "%%I %%J" == "Common Startup" if not "%%~L" == "" if "%%K" == "REG_SZ" (set "StartupFolder=%%~L") else if "%%K" == "REG_EXPAND_SZ" call set "StartupFolder=%%~L"
这两个批处理文件解决方案也适用于Windows XP,因为默认情况下文件夹名称依赖于Windows XP的语言,因此根本无法使用默认值。
在驱动器上搜索外壳文件夹总是获取外壳文件夹路径的错误方法。微软编写的任何Windows应用程序都不能做到这一点,因此任何批处理脚本都不应该这样做。