Solved

VBScript Permissions error

Posted on 2011-02-22
14
355 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 
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 100 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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Make the most of your online learning experience.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

717 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