Windows XP environment variable for "local setting" folder
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.
Kiran PS
Updated on September 17, 2022Comments
-
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 almost 14 yearsNote that this depends on the language of the OS and thus is a very poor solution to the problem.
-
user1984103 almost 14 yearsThis is version-specific, and would not function on Windows Vista or Windows 7. %LOCALAPPDATA% Should work for them, though.
-
James almost 14 yearsDarth Android, the question specified Windows XP. As for a language independent way of getting the path, Johannes' solution is indeed superior
-
Joey over 13 yearsYou did spot the glaring »Do not use this registry key« message in there?
-
Mehrdad Mirreza over 13 yearsWhere should I have seen that? Who said "Do not use this registry key" ?
-
avirk over 11 yearsIts not clear for anyone how you want to help the others through your post.
-
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 about 8 yearsThanks, this works perfectly and should have been the accepted answer.