I have a working VBScript that deletes old symantec AV defs from servers that have less than 3 GB free on the C drive. On a couple of servers, the old virus defs are locked by the service and they can't be deleted. The obvious solution is to stop the service, then delete the folder in question. Everything else in the script works perfectly.
What I have done is added If err.number <> 0 then call a sub that will stop the service, delete folder, start service (right now it just echos an ERROR line).
What I am running into is that when the script attempts to delete the file, gets an error, and then script then jumps to the next server in the list, so it never gets to the line with if err.number <> 0. It also doesn't finish checking the rest of the files in that folder. On Error Resume Next is set at the beginning of the script.
Here is the part of the code in question:
If oSubFolder.Name <> oNewestFolder Then
Wscript.Echo "Deleting : " & oSubFolder.Name
ResFile.writeline vbtab & vbtab & "DELETING " & oSubFolder.Name & vbtab & oSubfolder.DateCreated & vbtab & oSubfolder.size
IF Err.number <> 0 Then
wscript.echo vbtab & vbtab & "*ERROR* Need to stop Symantec Service"
ResFile.writeline vbtab & vbtab & "*ERROR* Need to stop Symantec Service"