Windows XP environment variable for "local setting" folder

20,507

Solution 1

For temporary changes you can use set command that can be used in scripts or in the command window.

More permanent changes can be made via the System properties dialog box by doing right-click on My Computer -> Properties and in the Advanced tab select Environment Variables. From there you can create new path variables to use.

There are also other ways to accomplish this task, see more info here

Solution 2

This is very cryptical, but it works with standard Windows XP commands:

for /f "tokens=4,5 delims=\" %a in ('reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "Local AppData"^|find "REG_SZ"') do set LocalAppData=%userprofile%\%a\%b

... and it is language independent (use %%a and %%b instead of %a and %b inside batch files).

Solution 3

There isn't such a variable on legacy Windows versions. However, you can get the folder path through VBScript:

Set objShell = CreateObject("Shell.Application")
WScript.Echo objShell.Namespace(&H1c&).Self.Path

You can then use this in a batch file as follows:

for /f "delims=" %%i in ('cscript /nologo localappdata.vbs') DO (
  set LOCALAPPDATA=%%i
)

On current versions of Windows this variable (%LOCALAPPDATA%) exists by default.

Solution 4

There isn't one by default, though you can type set into a command prompt to see a list of all environment variables on your system.

An alternative for you is to use %USERPROFILE%\Local Settings and %USERPROFILE%\Local Settings\Application Data or set your own environment variables with the set command.

Share:
20,507
Kiran PS
Author by

Kiran PS

Updated on September 17, 2022

Comments

  • Kiran PS
    Kiran PS over 1 year

    There's an environment variable, %appdata%, equal to

    C:\Documents and Settings\<username>\Application Data\
    

    Is there a variable for either

    C:\Documents and Settings\<username>\Local Settings\
    

    or

    C:\Documents and Settings\<username>\Local Settings\Application Data\
    

    ?

  • Joey
    Joey almost 14 years
    Note that this depends on the language of the OS and thus is a very poor solution to the problem.
  • user1984103
    user1984103 almost 14 years
    This is version-specific, and would not function on Windows Vista or Windows 7. %LOCALAPPDATA% Should work for them, though.
  • James
    James almost 14 years
    Darth Android, the question specified Windows XP. As for a language independent way of getting the path, Johannes' solution is indeed superior
  • Joey
    Joey over 13 years
    You did spot the glaring »Do not use this registry key« message in there?
  • Mehrdad Mirreza
    Mehrdad Mirreza over 13 years
    Where should I have seen that? Who said "Do not use this registry key" ?
  • avirk
    avirk over 11 years
    Its not clear for anyone how you want to help the others through your post.
  • hakre
    hakre over 11 years
    @MehrdadMirreza: It is suggested to not access the registry for this, please see blogs.msdn.com/b/oldnewthing/archive/2003/11/03/55532.aspx for an explanation. - See as well: How can I get the path of a Windows “special folder” for a specific user?
  • Tony
    Tony about 8 years
    Thanks, this works perfectly and should have been the accepted answer.