Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 371
  • Last Modified:

VBScript Permissions error

Hi...I have a VB Script that is used to delete files after a certain amount of days have gone by.  Currently it is at 5 days.  I think it is a permissions problem but I've given that drive, folder, subfolders, child objects, etc....full permissions to everyone and anyone possible.  Yet when I run the script, it gives me a Permission Denied error on Line 16, Char 10.  Which is the fso.delete command.  I have attached an image of the error and the vb script text is pasted below:

vberror
Dim fso, startFolder, OlderThanDate
 
Set fso = CreateObject("Scripting.FileSystemObject")
startFolder = "F:\backups" ' folder to start deleting (subfolders will also be cleaned)
OlderThanDate = DateAdd("d", -5, Date)  ' 5days (adjust as necessary)
 
DeleteOldFiles startFolder, OlderThanDate
 
Function DeleteOldFiles(folderName, BeforeDate)
   Dim folder, file, fileCollection, folderCollection, subFolder
 
   Set folder = fso.GetFolder(folderName)
   Set fileCollection = folder.Files
   For Each file In fileCollection
      If file.DateLastAccessed < BeforeDate Then
         fso.DeleteFile(file.Path)
      End If
   Next
 
    Set folderCollection = folder.SubFolders
    For Each subFolder In folderCollection
       DeleteOldFiles subFolder.Path, BeforeDate
    Next
End Function


Thanks in  advance for your help.
0
ryan_johnston
Asked:
ryan_johnston
2 Solutions
 
ryan_johnstonAuthor Commented:
I should add that I have this same script on multiple servers on different domains and get the same error.  Also, if theres a better/easier script that will accomplish this, then I am open to suggestions.
0
 
prashanthdCommented:
Hi,

Can you add the following line at top of code, to confirm if issue with one file or all files

On Error Resume Next
0
 
ryan_johnstonAuthor Commented:
I didn't get the error that time when I added that line but nothing was deleted.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
prashanthdCommented:
Can you check if you are able to manually delete any of the files?
0
 
ryan_johnstonAuthor Commented:
Interesting...I used to be able to...now I cannot.  That makes me think it's definitely a permissions problem but I'm logged in as admin and Everyone, Administrators, Domain Admins, Domain Users, and Users have full control.  There are no deny entries in the permissions and the owner is administrator.
0
 
ryan_johnstonAuthor Commented:
I can create a new folder in that same directory and then delete it just fine.  Does Backup Exec put any kind of permissions on those folders?
0
 
prashanthdCommented:
You can use process explorer to check if the files are being used by any application

http://technet.microsoft.com/en-us/sysinternals/bb896653
0
 
ryan_johnstonAuthor Commented:
There wasn't anything keeping them open.  So on a whim I went and removed the drive from the device manager then went and unplugged the drive and plugged it back in.  I was now able to delete the files manually and the script worked as well without any errors.
0
 
connectexCommented:
Try this for areas where the code could fail:


On Error Resume Next
objFile.Delete
If Err Then WScript.Echo sstrTest & "ERROR - " & Err.Description & ": " & objFile.Name & vblf
On Error GoTo 0

Open in new window

0
 
prashanthdCommented:
It is quite obvious that the files have been locked by an application/OS, for reasons unknown and my comments have helped to confirm the same, also there was never an issue with the script.

0
 
ryan_johnstonAuthor Commented:
Yet the process explorer didn't show me anything that had them in use.
0
 
modus_operandiCommented:
Starting auto-close process to implement the recommendations of the participating Expert(s).
 
modus_operandi
EE Admin
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now