On Error Resume Next
Const ForReading = 1
Const OverWriteExisting = TRUE
Const ForWriting = 2, ForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
'*******************************************************************************
' Set this path to the ABSOLUTE location of your list of computer names (one computer name per line)
'*******************************************************************************
Set objFile = objFSO.OpenTextFile("{ABSOLUTE}\computers.txt")
Set WshShell = WScript.CreateObject("WScript.Shell")
Do Until objFile.AtEndOfStream
strComputer = objFile.ReadLine
'*******************************************************************************
' This will check to see if the computer is even on the network
'*******************************************************************************
Set WshExec = WshShell.Exec("ping -n 3 -w 2000 " & strComputer)
strPingResults = LCase(WshExec.StdOut.ReadAll)
If InStr(strPingResults, "reply from") Then
'*******************************************************************************
' If the computer is live on the network, let's determine if it is a Windows XP or Windows 7
' Note: It is relatively easy to add additional versions should your network, for some reason, have more
'*******************************************************************************
Set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMI.ExecQuery("Select * from Win32_OperatingSystem",,48)
For Each objItem in colItems
VerBig = Left(objItem.Version,3)
Next
Select Case VerBig
Case "6.1"
OSystem = "7"
userPath = "\\" & strComputer & "\c$\Users"
appPath = "AppData\Local\Apps\2.0"
Case "5.1"
OSystem = "XP"
userPath = "\\" & strComputer & "\d$\Documents and Settings"
appPath = "Local Settings\Apps\2.0"
Case Else OSystem = "Invalid OS"
End Select
'*******************************************************************************
' You and uncomment this line to be prompted with the machines OS before proceeding (made for testing)
'*******************************************************************************
' Wscript.Echo "The OS version for " & strComputer & " is Win " & OSystem
sProfile = WshShell.ExpandEnvironmentStrings(userPath)
sProfileRoot=objFSO.GetFolder(sProfile)
set objProfileFolder=objFSO.GetFolder(sProfileRoot)
'*******************************************************************************
' Using the "userPath" and "appPath" variable defined by the OS version, the script will delete the folder
' userPath\*\appPath (the * is only for a single directory level)
'*******************************************************************************
for each objFolder in objProfileFolder.SubFolders
sProfile = sProfileRoot & "\" & objFolder.Name & "\" & appPath
Set FSO = CreateObject("Scripting.FilesystemObject")
FSO.DeleteFolder(sProfile)
'*******************************************************************************
' This is a troubleshooting set of lines meant to ensure the paths being generated by the script for
' deletion are what you want
'*******************************************************************************
' Set QTPfile = FSO.OpenTextFile("D:\Documents and Settings\chris.esbrandt\Desktop\profiles2.txt", ForAppending, True)
' QTPfile.WriteLine(sProfile & vbCr)
' QTPfile.Close
next
'*******************************************************************************
' Else If machine == OFFLINE Then add the machine name to a list of offline machines (again, ABSOLUTE
' path is needed)
'*******************************************************************************
Else
Set FSO = CreateObject("Scripting.FilesystemObject")
Set QTPfile = FSO.OpenTextFile("{ABSOLUTE}\offlineComputers.txt", ForAppending, True)
QTPfile.WriteLine(strComputer & vbCr)
QTPfile.Close
End If
Loop