VB works in 2k, Not in 2k3 - Experts please help!

Hi! I am no VB programmer whatsoever... but I manage around 15 Citrix Metaframe XPE servers currently running 2k. I publish office apps and a few small proprietary applications and have to do a reboot every night of all the servers and have a group policy startup/shutdown script that applies to that active directory group to clean out all of the users profiles except for the important administator, default user, all users, etc. This has worked fine with no hitch for years but we will be upgrading to 2k3 next weekend and I have a test 2k3 box installed with citrix in the same group and this script no longer works. All of the profiles are there every morning and there are no error messages in the event viewer about the script. Do I need to change something in this script to make it work for 2k3? I made sure the documents and setting folder has way more full access rights than we need just to make it work... I don't think that is it. I appreciate any insight you can give and thanks in advance. Below is the script:


'*****************************************************************************************************
'* VBScript for DELETEING Files and Folders in C:\Documents and Settings
'*
'* - Does not delete the folders: "All Users" , "Default User" , "Administrator" and "Administrator.Amedisys-DOM"
'*****************************************************************************************************

'* folder to delete files and subfolders from
Const MainFolder = "C:\Documents and Settings"

Dim fso, f, fc, FileToDelete, sf, FolderToDelete
Set fso = CreateObject("Scripting.FileSystemObject")

'* if the folder you are deleteing files and subfolders from is not available do nothing
IF fso.FolderExists(MainFolder) Then

'* Delete Files in C:\Documents and Settings
Set f = fso.GetFolder(MainFolder)
Set fc = f.Files
If fc.Count <> 0 Then
For Each file in fc
Set FileToDelete = fso.GetFile(file)
fso.DeleteFile FileToDelete, TRUE
Next
End If

'* Delete SubFolders in C:\Documents and Settings
Set sf = f.SubFolders
If sf.Count <> 0 Then
For Each fl in sf
If UCase(fl.Name) <> "NetworkService" AND UCase(fl.Name) <> "LocalService" AND UCase(fl.Name) <> "ALL USERS" AND UCase(fl.Name) <> "DEFAULT USER" AND UCase(fl.Name) <> "ADMINISTRATOR" AND UCase(fl.Name) <> "ADMINISTRATOR.AMEDISYS-DOM" Then
Set FolderToDelete = fso.GetFolder(fl)
fso.DeleteFolder FolderToDelete, TRUE
End If
Next
End If

End If


Thanks again!
Spencer

[2905 byte] By [SpencerInLa] at [2007-12-16]
# 1
For what it's worth, 2003 installs out of the box locked down, i.e. most everything is turned off or not installed for security reasons. It sounds like you may just need to turn on scripting somewhere, or install the Windows Scripting Host.

Good luck.

AlexB-007 at 2007-9-8 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2
Hi Spencer !!!

Regarding your VBS, I believe there is a small error that can give you a BIG problem...
At the end of the code, where it deletes the SUBFOLDERS, there is an IF clause:

If UCase(fl.Name) <> "NetworkService" AND UCase(fl.Name) <> "LocalService" AND UCase(fl.Name) <> "ALL USERS" AND UCase(fl.Name) <> "DEFAULT USER" AND UCase(fl.Name) <> "ADMINISTRATOR" AND UCase(fl.Name) <> "ADMINISTRATOR.AMEDISYS-DOM" Then

You should replace this part to match the condition you are checking (UCASE). The corret would be:

If UCase(fl.Name) <> "NETWORKSERVICE" AND UCase(fl.Name) <> "LOCALSERVICE" AND UCase(fl.Name) <> "ALL USERS" AND UCase(fl.Name) <> "DEFAULT USER" AND UCase(fl.Name) <> "ADMINISTRATOR" AND UCase(fl.Name) <> "ADMINISTRATOR.AMEDISYS-DOM" Then

This way VBS won't delete any undesired SUBFOLDER. Big Smile

Regards,
Flima.

Flima at 2007-9-8 > top of Msdn Tech,Visual Basic,Visual Basic General...