Questions

VBS Delete Script Access Denied

+
0 Votes
Locked

VBS Delete Script Access Denied

james.carver
Im trying to write a scrip that will allow me to delete the contents of a folder remotely although when it runs accross a file that is locked or in use it errors out and stops. Is there a way to have it skip that one file and move on to the next.
+
0 Votes
james.carver
Collapse -

I cant use resume next because I am trying to delete the contents of a folder. If i use resume next it will move to the next line in my script. I really need it to just move to the next file if possible. Below is a copy of what I have so you can get an Idea of what im working with.

dim message, title, wackwack, path, windows, temp, history, temporary_internet_files, temp_delete, history_delete, temporary_internet_files_delete

message = "Enter the Service Tag of the PC you want to clean."
title = "PC Cleaner"
wackwack = "\\"
path = "\C$\Documents and Settings\"
windows = "\C$\WINDOWS\temp\*"
temp = "\local settings\temp"
temporary_internet_files = "\local settings\Temporary Internet Files"
temp_delete = "\local settings\temp\*"
temporary_internet_files_delete = "\local settings\Temporary Internet Files\*"

servicetag=InputBox(message, title)

Set fso = CreateObject("Scripting.FileSystemObject")

Set folder = fso.GetFolder(wackwack & servicetag & path)

Set subFolders = folder.SubFolders

For Each folderObject in SubFolders

If fso.FolderExists(wackwack & servicetag & path & folderobject.name & temp) Then
fso.DeleteFolder wackwack & servicetag & path & folderobject.name & temp_delete, True
fso.DeleteFile wackwack & servicetag & path & folderobject.name & temp_delete, True
End If

If fso.FolderExists(wackwack & servicetag & path & folderobject.name & temporary_internet_files) Then
fso.DeleteFolder wackwack & servicetag & path & folderobject.name & temporary_internet_files_delete, True
fso.DeleteFile wackwack & servicetag & path & folderobject.name & temporary_internet_files_delete, True
End If

Next

fso.deletefolder wackwack & servicetag & windows,True
fso.DeleteFile wackwack & servicetag & windows, True

Set subFolders = Nothing
Set folder = Nothing
Set fso = Nothing