Question Locked

retrieve local user profile path with vbscript

0 helpful
4 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I need a windows vbscript to retrieve local user profile path.

Thanks

4 replies

by chris910

this will print the profile path in DOS

echo %userprofile%

I suspect that the same system variable is available in VBScript.

by dan.cox

Const HKEY_LOCAL_MACHINE = &H80000002
Set objRegistry=GetObject("winmgmts:\\" & strLocalPC & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubkeys
For Each objSubkey In arrSubkeys
strValueName = "ProfileImagePath"
strSubPath = strKeyPath & "\" & objSubkey
objRegistry.GetExpandedStringValue HKEY_LOCAL_MACHINE,strSubPath,strValueName,strValue
LogAction "Deleting Temporary Internet files for " & strValue & "\Local Settings\Temporary Internet Files\*.*"
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile(strValue & "\Local Settings\Temporary Internet Files\*.*")
Next

by thoades

You can call any DOS "environment" variable using the following method within VBS without having to interrogate AD

Set objShell = CreateObject("WScript.Shell")
userProfilePath = objShell.ExpandEnvironmentStrings("%UserProfile%")

just swap the "%UserProfile%" in the above line to which ever DOS environment variable it is you need.

This discussion is closed to new replies.