Link to home
Start Free TrialLog in
Avatar of aridaen
aridaenFlag for United States of America

asked on

VB Script for roaming profile cleanup


My issue is that in my roaming profile folder, there are 2 or 3 profile folders for each user, some obvious as they are marked with bad or old.  However, I need to find out which is the actual profile folder used by the user so I can remove the others.  I have been working with the script below and have not been able to get it to work correctly while reading a list of computer names.  As it is currently written, the script only records the registry values for the last computer in the list.  What am I missing?

' Set the constants
Const HKEY_LOCAL_MACHINE = &H80000002
Const ForAppending = 8

' Create FileSystemObject
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile2 = objFSO.OpenTextFile("c:\profilelist.txt", ForAppending)

'Read the server list
Const ForReading = 1

Set objDictionary = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("c:\computers.txt", ForReading)
i = 0

Do Until objTextFile.AtEndOfStream
    strComputer = objTextFile.Readline
    objDictionary.Add i, strComputer
    i = i + 1

Set objRegistry=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
    strComputer & "\root\default:StdRegProv")

objTextFile2.WriteLine("PC Name: " & strComputer)

strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubkeys

For Each objSubkey In arrSubkeys
    strValueName = "CentralProfile"
    strSubPath = strKeyPath & "\" & objSubkey
    objRegistry.GetExpandedStringValue HKEY_LOCAL_MACHINE,strSubPath,strValueName,strServerPath
    If strServerPath <> "" then
        strValueName = "ProfileImagePath"
        strSubPath = strKeyPath & "\" & objSubkey
        objRegistry.GetExpandedStringValue HKEY_LOCAL_MACHINE,strSubPath,strValueName,strValue
        'Wscript.Echo strValue & " is stored centrally on " & strServerPath
      objTextFile2.WriteLine("Current CentralProfile Value: " & strServerPath)
    END IF


Avatar of sungenwang
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of aridaen


Yes, the result of frustration and a long day.  Thank you, this works.