We help IT Professionals succeed at work.
Get Started

VB Script for roaming profile cleanup

aridaen
aridaen asked
on
820 Views
Last Modified: 2012-07-09
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
Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE