yzharovsky Posted September 17, 2008 Share Posted September 17, 2008 (edited) Greetings AllI am running a VB script to delete folders which are not "Administrator" "All Users" or "Default Users"The Script works fine in every folder except for "Documents and Settings"In "Test" directories it will delete everything except for the folders listed above; as it should.However once I run the scrip against directory "Documents and Settings" the script will generate an error if there are folders which start with the letter "M" or any letter there after. (Please note that you can create a folder starting with the letter M in Documents and Settings and you will get the error, it seems that the error has nothing to do with profile folders but just folder names.)Example " folder with the letter "A" such as "Aaaa" will be deleted however folder "Mmmmm" or "mmmb" or "mom" will not be delete and the script will generate an error of "Access Denied" ( There is no error or problem against locked folders such as Administrator )I also did some tests and figured out that it’s not even the letter "M" that is the issue, the issue starts with folder name "Loo" So folder name "L" will be deleted while folder "Lz" will give me an error.Here is the scriptYou can look at it and even try it yourself.I know Documents and Settings folder is very special, what I want to know is how and what change is made to Documents and Settings vs other folders.I did get my script to work, by inserting a "Resume on Error" command and it does then delete all the folders including the ones starting with M.But I still am very curious.CheersYevgenyThis one will generate the error in Documents and Settings I commented out the part that fixes the error.Set fso=CreateObject("Scripting.FileSystemObject")CleanPath="C:\Documents and Settings\"For Each file In fso.GetFolder(CleanPath).Filesfile.attributes = file.attributes And Not 1file.deleteNextSet fso = CreateObject("Scripting.FileSystemObject")Set oFolder = fso.GetFolder("C:\Documents and Settings\")arrFolders = Array()For Each oFolder In oFolder.SubFolders' Note : Only use *lowercase* letters in the folder names below:If Not LCase(oFolder.Name) = "administrator" _And Not LCase(oFolder.Name) = "all users" _And Not LCase(oFolder.Name) = "default user" ThenintCount = UBound(arrFolders) + 1ReDim Preserve arrFolders(intCount)arrFolders(intCount) = oFolder.PathEnd IfNextFor n = 0 To UBound(arrFolders)' On Error Resume Next fso.DeleteFolder arrFolders(n), TrueNext Edited September 17, 2008 by yzharovsky Link to comment Share on other sites More sharing options...
Yzöwl Posted September 17, 2008 Share Posted September 17, 2008 First of all I'd expect something like this to work!Set oFSO = CreateObject("Scripting.FileSystemObject")Set oFolder = oFSO.GetFolder("C:\Documents and Settings")For Each Profile In oFolder.SubFolders Select Case UCase(Profile.Name) Case "ADMINISTRATOR", "ALL USERS", "DEFAULT USER" 'Do nothing Case Else oFSO.DeleteFolder Profile.Path, True End SelectNextYou would of course need to be logged in as Administrator!Second of all I'd suggest you use a specific utility such as Microsofts Resource Kits tool, DelProf, for such a task. Link to comment Share on other sites More sharing options...
yzharovsky Posted September 17, 2008 Author Share Posted September 17, 2008 Greetings YzöwlThank you for your replyI have ran your script and wanted to let you know that it too errors out in Documents and Settings on folders starting with the letter "mz".I am running this script on my local machine and I am logged in as Administrator, also keep in mind that the folder starting with mz was created by me and has nothing inside the folder (the folder is empty)You can easily try your script on your own machine, just make sure you are pointing it to Documents and Settings because the script does work in any other folder.Thank you again for your replyCheersYevgeny Link to comment Share on other sites More sharing options...
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