troubleshooting Question

VB Script for roaming profile cleanup

Avatar of aridaen
aridaenFlag for United States of America asked on
VB Script
2 Comments1 Solution821 ViewsLast Modified:
Hi,

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
Loop


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
Next
 


objTextFile2.WriteLine(vbCrLf)

objTextFile2.Close
ASKER CERTIFIED SOLUTION
sungenwang

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros