Is there any environment variable representing the "C: \ Documents and Settings" folder or the C: \ Users folder on Windows?

Is there any environment variable or other format which profile path is represented in Windows? I want to query in such a way as to get the value "C: \ Documents and Settings" (if Windows XP or 2k3) or C: \ users (if Vista or Windows 7).

I do not want the current username to be added to the string that I can get through %% USERPROFILE%.

+6
javascript windows environment-variables
source share
5 answers

He does not exist. Instead, try %USERPROFILE%\..

Warning: as @Mark points out, this is unreliable because the user profile directory may indeed be an arbitrary location.

+9
source share

In Vista +, you can use FOLDERID_UserProfiles to get C: \ Users (or what might be in localized versions, etc.). In XP and earlier, you will have to go along the CSIDL_COMMON_DESKTOPDIRECTORY path, which will give you "C: \ Documents and Settings \ All Users \ Desktop" and work from there.

I think this solves this for Vista. For XP, the solution is not perfect, but at least it will not depend on the current path of the user profile. "All users" will always exist, and I can’t think of a reason for it to be in a place other than the standard one.

+3
source share

As far as I know, no, but you can make the last instance of "/" to find the parent directory% USERPROFILE%

+2
source share

Yes, there really is a way to make it work:

 %USERPROFILE%\.. 
+2
source share

I got batch and VBS methods (see below) since I could not find the equivalent package or VBS method for this question elsewhere. If I do not add it to this stream (jscript), add a comment about how / where it should go, and I will remove this answer and post as indicated. :)

Package (one line - carriage return):

 for /f "tokens=2*" %%f in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" /v ProfilesDirectory ^|find /i "Profiles"') do @set ProfDir=%%g 

VBScript:

 ' http://www.activexperts.com/activmonitor/windowsmanagement/adminscripts/registry/#ListRegFiles.htm const HKEY_LOCAL_MACHINE = &H80000002 strComputer = "." Set StdOut = WScript.StdOut Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_ strComputer & "\root\default:StdRegProv") strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" oReg.EnumValues HKEY_LOCAL_MACHINE, strKeyPath,_ arrValueNames, arrValueTypes For i=0 To UBound(arrValueNames) ' StdOut.WriteLine "File Name: " & arrValueNames(i) & " -- " oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,_ arrValueNames(i),strValue ' StdOut.WriteLine "Location: " & strValue ' StdOut.WriteBlankLines(1) IF arrValueNames(i) = "ProfilesDirectory" THEN ProfileRoot= strValue Next wscript.echo("ProfileRoot=" & ProfileRoot) 
0
source share

All Articles