timbo343 Posted September 19, 2007 Posted September 19, 2007 Can anyone advise me on how to delete multiple folders from docs and settings, but am wanting the script to keep: All Users; Administrator; Default User and sophos. So far i have the basic: Set objFSO = CreateObject("Scripting.FileSystemObject") objFSODeleteFolder("C:\.....") What do i need to add from here? Thanks
webman Posted September 19, 2007 Posted September 19, 2007 Here's a full script we use to remove profiles from Docs&Settings. On Error Resume Next Dim obtainfolder Dim Pathfinder Dim strPath Set fso = CreateObject("Scripting.FileSystemObject") strPath = "C:\Documents and Settings\" set excludefile = fso.OpenTextFile("\\bbs-svr-001\rmpublic\scripts\exclude.txt", 1) excludelist = excludefile.Readall 'msgbox excludelist Set f = fso.GetFolder(strPath) ' Loop through all subfolders For Each fldrItem in f.SubFolders fldrName = fldrItem.name If Right(strPath,1) <> "\" Then Pathfinder = strPath & "\" & fldrName Else Pathfinder = strPath & fldrName End If If InStr(1, excludelist, fldrName, 1) Then 'msgbox "Has not deleted " & fldrName Else 'msgbox "Deleting " & fldrName set obtainfolder = fso.GetFolder(Pathfinder) obtainfolder.Delete true End If 'End Select Next ' Clean up objects Set fso = Nothing Set fc = Nothing \\bbs-svr-001\rmpublic\scripts\exclude.txt contains a list of folders NOT to delete.
Geoff Posted September 19, 2007 Posted September 19, 2007 That's broken. You've not removed the registry entries.
OutToLunch Posted September 19, 2007 Posted September 19, 2007 I use a 1 line batch file, never got to grips with that new fangled VB script This only saves the All Users and Default User folder, but it should be apparent how to add others with another IF NOT. for /D %I IN ("C$\documents and settings\*") do @IF NOT "All Users"=="%~nI" IF NOT "Default User"=="%~nI" rmdir "%I" /s /q | echo %I With an extra FOR loop, you can have it run through a whole batch of remote machines in an ICT suite and do it from your workstation on demand... for /L %V in (1,1,9) DO for /D %I IN ("\\ict2-%V\C$\documents and settings\*") do @IF NOT "All Users"=="%~nI" IF NOT "Default User"=="%~nI" rmdir "%I" /s /q | echo %I Runs through ICT2-1 to ICT2-9 via UNC paths.
Geoff Posted September 19, 2007 Posted September 19, 2007 That's also broken. You must remove the registry entries for the profile when you remove the folder.
timbo343 Posted September 19, 2007 Author Posted September 19, 2007 so if i didnt want to delete the following folders: All Users; Administrator; Default User and sophos, where would i put these in the script. Is it easier to call a txt file like you have done? Also, what is the excludefile.readall? Is that a file that you have created?
webman Posted September 19, 2007 Posted September 19, 2007 Works OK for us. Which registry keys are you referring to specifically? Yes, just put "All Users; Administrator; Default User and sophos" in a text file (one per line) and specify the path to it as the exclude file.
tosca925 Posted September 19, 2007 Posted September 19, 2007 Save below in a vbs file. Please make sure you do not use this on staff laptops if they have a local user account becasue this will delete all their files. USE THIS SCRIPT WITH CARE...... Function Main() On Error Resume Next Dim obtainfolder Dim PathFolder Dim strPath Set fso = CreateObject("Scripting.FileSystemObject") strPath = "C:\Documents and Settings\" Set f = fso.GetFolder(strPath) ' Loop through all subfolders For Each fldrItem in f.SubFolders fldrName = fldrItem.name If Right(strPath,1) <> "\" Then PathFolder = strPath & "\" & fldrName Else PathFolder = strPath & fldrName End If Select Case fldrName Case "Administrator": Case "All Users": Case "Default User": Case "Sophos" Case Else: set obtainfolder = fso.GetFolder(PathFolder) obtainfolder.Delete true End Select Next ' Clean up objects Set fso = Nothing Set fc = Nothing End Function call Main()
timbo343 Posted September 19, 2007 Author Posted September 19, 2007 Whay, thanks. Nah i shallnt be using this on laptops, its for the techs so if they mess up an image or something is missing from an image it will delete any local profles the kids have created.
apeo Posted September 19, 2007 Posted September 19, 2007 Works OK for us. Which registry keys are you referring to specifically? I believe hes talking about: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList
tech_guy Posted September 19, 2007 Posted September 19, 2007 Ok I'm being thick here - what would happen if you deleted the folders but left the registry alone? (we always delete both btw when we purge systems)
Geoff Posted September 19, 2007 Posted September 19, 2007 Machine hangs at 'Loading your personal settings' at login.
PiqueABoo Posted September 19, 2007 Posted September 19, 2007 I wonder if credential caching makes the difference? Whatever, cleaning up the associated reg keys is neater. All you need then is some elusive magic to make any orphaned "hsperf" files and the like go away - things with nasty NTFS permissions requiring take ownership, files with illegal names etc.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now