Search code examples
windowsbatch-filecmd

Get Windows startup folder from CMD with different system language


I'm trying to get Windows (10/11) startup folder location in a system whose language is French.

Normally, I use this command to get the folder location:

set "startupFolder=%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup"
echo %startupFolder%

But when system language is French, the folder path is like below:

"%APPDATA%\Microsoft\Windows\Menu Démarrer\Programmes\Démarrage"

How can I make sure my command will return startup folder location in all languages, not just English or French?


Solution

  • You can get the location from the users registry branch HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders under the Startup value.

    Example:

    @Echo Off
    SetLocal EnableExtensions
    
    Set "UserBranch=HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders"
    Set "ShellFolder=Startup"
    
    Set "%ShellFolder%="
    For /F "EOL=H Tokens=1-2,*" %%G In ('%SystemRoot%\System32\reg.exe Query "%UserBranch%" /V "%ShellFolder%" 2^>NUL') Do Set "%%G=%%I"
    If Defined %ShellFolder% (Set %ShellFolder%) & Pause
    

    The above code however will not be directly changeable for all Values under the User Key, for example History, (due to ignoring End Of Lines beginning with H), and Local AppData, My Music, My Pictures, My Video, and Start Menu, (due to the space in their value names). The same would be true for Common AppData, Common Desktop, Common Documents, Common Programs, Common Start Menu, Common Startup, and Common Templates under the Machine Key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders.

    If you wish therefore to be able to use the code for those cases too, you could modify it to cater for all scenarios.

    Example:

    @Echo Off
    SetLocal EnableExtensions DisableDelayedExpansion
    
    Set "RootKey=HKEY_LOCAL_MACHINE"
    Set "ShellFolder=Common Start Menu"
    
    Set "Branch=\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders"
    Set "%ShellFolder: =_%="
    For /F "Tokens=1-2,*" %%G In ('%SystemRoot%\System32\reg.exe Query "%RootKey%%Branch%" /V "%ShellFolder%" 2^>NUL') Do (
        If "%%H" == "REG_EXPAND_SZ" (Set "%%G=%%I") Else (Set "_=%%I"
            SetLocal EnableDelayedExpansion
            For /F "Tokens=*" %%J In ("!_:*REG_EXPAND_SZ=!") Do EndLocal & Set "%ShellFolder: =_%=%%J"
        )
    )
    If Defined %ShellFolder: =_% (Set %ShellFolder: =_%) & Pause