4 ms·
> I'm pretty sure PATH, USER, and HOME work everywhere. Out of those 3 only PATH works on Windows. Windows has a USERNAME environment variable, but depending
by tssva 3y ago
> I'm pretty sure PATH, USER, and HOME work everywhere.
Out of those 3 only PATH works on Windows.
Windows has a USERNAME environment variable, but depending on your needs you may need to combine it with the USERDOMAIN variable to get the complete username, %USERDOMAIN%\%USERNAME%.
Windows has a HOMEPATH environment variable but it contains only the directory for the home folder. Another variable, HOMEDRIVE, contains the drive the home directory exists on, so the complete home location is %HOMEDRIVE%\%HOMEPATH%. In powershell a read-only HOME variable is set pointing to %HOMEDRIVE%\%HOMEPATH%. The home directory is supposed to store user files. User specific applications, OS components, customization and configuration data should be stored in the USERPROFILE directory. This is very frequently but not always the same as %HOMEDRIVE%\%HOMEPATH%.
- joombaga 3y agoIn what circumstance would USERPROFILE differ from HOMEDRIVE\HOMEPATH?
- tssva 3y agoWhen users home folders are redirected to a network share. In that circumstance it is also possible that the user's home directory might be HOMESHARE\HOMEPATH instead of HOMEDRIVE\HOMEPATH. This will be the case if the network share isn't mapped to a drive letter. Really HOMESHARE should be checked for and only if it doesn't exist HOMEDRIVE used. I should have pointed that out in my original comment but it was made pre-coffee. Folder redirection is used often in conjunction with remote desktop services, virtual desktops or just to centralize file storage for ease of backup.