There is no need to search for a folder named Startup
in all directories of a drive.
There are by default since Windows Vista:
%ALLUSERSPROFILE%\Microsoft\Windows\Start Menu\Programs\Startup
This is the common startup folder in start menu for all users.
%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup
This is the startup folder in start menu of current user.
A batch file to get the really used Startup folder of current user is:
@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 "%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup"
echo Startup folder of current user is:
echo "%StartupFolder%"
endlocal
For a full explanation of this code read this answer with same batch file code used to get the real Desktop folder of current user. I have just replaced all occurrences of Desktop
by Startup
to change the code for the Startup shell folder.
A batch file to get the really used Common Startup folder for all users is:
@echo off
setlocal EnableExtensions DisableDelayedExpansion
set "StartupFolder="
for /F "skip=1 tokens=2,3*" %%I in ('%SystemRoot%\System32\reg.exe QUERY "HKLM\Software\Microsoft\Windows\CurrentVersion\Explorer\User 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%\System32\reg.exe QUERY "HKLM\Software\Microsoft\Windows\CurrentVersion\Explorer\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 set "StartupFolder=\"
if "%StartupFolder:~-1%" == "\" set "StartupFolder=%StartupFolder:~0,-1%"
if not defined StartupFolder set "StartupFolder=%ALLUSERSPROFILE%\Microsoft\Windows\Start Menu\Programs\Startup"
echo Common startup folder for all users is:
echo "%StartupFolder%"
endlocal
The two FOR command lines could be also:
for /F "skip=1 tokens=1-3*" %%I in ('%SystemRoot%\System32\reg.exe QUERY "HKLM\Software\Microsoft\Windows\CurrentVersion\Explorer\User 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%\System32\reg.exe QUERY "HKLM\Software\Microsoft\Windows\CurrentVersion\Explorer\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"
The two batch file solutions work also on Windows XP where the defaults cannot be used at all as the folder names are language dependent on Windows XP by default.
Searching for a shell folder on a drive is always the wrong approach to get the path of a shell folder. No Windows application written by Microsoft does that and so also no batch script should do that ever.