Questions

retrieve local user profile path with vbscript

+
0 Votes
Locked

retrieve local user profile path with vbscript

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

Thanks
  • +
    0 Votes
    Chris910

    this will print the profile path in DOS

    echo %userprofile%

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

    +
    0 Votes
    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

    +
    0 Votes
    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.

  • +
    0 Votes
    Chris910

    this will print the profile path in DOS

    echo %userprofile%

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

    +
    0 Votes
    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

    +
    0 Votes
    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.