Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VBScript Permissions error

Posted on 2011-02-22
14
Medium Priority
?
365 Views
Last Modified: 2012-05-11
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
Comment
Question by:ryan_johnston
14 Comments
 
LVL 8

Author Comment

by:ryan_johnston
ID: 34953716
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
 
LVL 12

Expert Comment

by:prashanthd
ID: 34953816
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
 
LVL 8

Author Comment

by:ryan_johnston
ID: 34953834
I didn't get the error that time when I added that line but nothing was deleted.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 12

Expert Comment

by:prashanthd
ID: 34954210
Can you check if you are able to manually delete any of the files?
0
 
LVL 8

Author Comment

by:ryan_johnston
ID: 34954406
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
 
LVL 8

Author Comment

by:ryan_johnston
ID: 34954433
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
 
LVL 12

Assisted Solution

by:prashanthd
prashanthd earned 400 total points
ID: 34954543
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
 
LVL 8

Accepted Solution

by:
ryan_johnston earned 0 total points
ID: 34954877
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
 
LVL 13

Expert Comment

by:connectex
ID: 34958216
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
 
LVL 12

Expert Comment

by:prashanthd
ID: 34960710
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
 
LVL 8

Author Comment

by:ryan_johnston
ID: 34962494
Yet the process explorer didn't show me anything that had them in use.
0
 
LVL 1

Expert Comment

by:modus_operandi
ID: 34995591
Starting auto-close process to implement the recommendations of the participating Expert(s).
 
modus_operandi
EE Admin
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Six Sigma Control Plans

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question