Is there any environment variable or Other format that the profile path is represented in Windows? I want to query in such a way that I should get the value "C:\Documents and Settings (if windows XP or 2k3) or C:\users (If vista or windows 7).
I dont want the current user name appended to the string, which I can get thru %USERPROFILE% variable.
I derived the batch and VBS methods (below), since I couldn't find an equivalent batch or VBS method for this question anywhere else. If I shouldn't add it to this thread (jscript), please add a comment on how/where it should go, and I will delete this answer and post as directed. :)
Batch (single line - no carriage return):
VBScript:
It doesn't exist. Instead, try
%USERPROFILE%\..
Warning: as @Mark suggests, this is not reliable because the user profile directory may really be any arbitrary location.
To the best of my knowledge no but you can do a last instance of '/' to find the parent directory of %USERPROFILE%
Yeah there actually is a way to get it to work:
On Vista+ you can use FOLDERID_UserProfiles to get C:\Users (or whatever it may be in localized versions, etc). On XP and earlier you'll pretty much have to go the CSIDL_COMMON_DESKTOPDIRECTORY route that will give you "C:\Documents and Settings\All Users\Desktop" and work your way back from there.
I think this settles it for Vista. For XP the solution is not perfect, but at least it won't depend on the current user's profile path. "All Users" will always exist, and I can't think of a reason for it to be in a place other than the default.