+ Post New Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
Coding Thread, FileSystemObject Folder why permission denied in Coding and Web Development; I have trying to create a script in VBS to delete oversized folders but both the DeleteFolder and Size methods ...
  1. #1

    Join Date
    Feb 2006
    Posts
    1,187
    Thank Post
    0
    Thanked 1 Time in 1 Post
    Rep Power
    0

    FileSystemObject Folder why permission denied

    I have trying to create a script in VBS to delete oversized folders but both the DeleteFolder and Size methods give a Permission Denied error even though I full access to the folder tree in question.

    Anybody come across this behaviour before?

  2. #2

    Join Date
    Feb 2007
    Location
    Norwich, Norfolk
    Posts
    8
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Re: FileSystemObject Folder why permission denied

    How are you running the script?

  3. #3

    Join Date
    Feb 2006
    Posts
    1,187
    Thank Post
    0
    Thanked 1 Time in 1 Post
    Rep Power
    0

    Re: FileSystemObject Folder why permission denied

    Code:
    cscript foobar.vbs
    No fancy XML stuff just yet

  4. #4

    Join Date
    Feb 2007
    Location
    Norwich, Norfolk
    Posts
    8
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Re: FileSystemObject Folder why permission denied

    Sorry, I meant are you running it as part of a scheduled task or logon script or something?

  5. #5
    apeo's Avatar
    Join Date
    Sep 2005
    Location
    Lost
    Posts
    1,612
    Thank Post
    95
    Thanked 115 Times in 111 Posts
    Rep Power
    42

    Re: FileSystemObject Folder why permission denied

    You may want to check that everything under the root folder is inheriting permissions or you have sufficient permissions. Also are you forcing the delete as it is set at false by default.

  6. #6

    Join Date
    Feb 2006
    Posts
    1,187
    Thank Post
    0
    Thanked 1 Time in 1 Post
    Rep Power
    0

    Re: FileSystemObject Folder why permission denied

    Quote Originally Posted by Jonno
    Sorry, I meant are you running it as part of a scheduled task or logon script or something?
    nope interactive while logged as admin. The folders were on a remote share if that makes any difference.

    The funning thing is though I could quite happily delete folders usins the RD /S batch command in a CMD sub shell.

  7. #7

    Join Date
    Feb 2006
    Posts
    1,187
    Thank Post
    0
    Thanked 1 Time in 1 Post
    Rep Power
    0

    Re: FileSystemObject Folder why permission denied

    I think the problem might be because the size and delete methods of a folder object cannot act on a folder more than 1 level deep.

    You'd think the Microsoft programers could just make use of few recursive system calls

  8. #8

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,156
    Thank Post
    116
    Thanked 529 Times in 452 Posts
    Blog Entries
    2
    Rep Power
    124

    Re: FileSystemObject Folder why permission denied

    Quote Originally Posted by NetworkGeezer
    I think the problem might be because the size and delete methods of a folder object cannot act on a folder more than 1 level deep.

    You'd think the Microsoft programers could just make use of few recursive system calls
    Works recursively here. Could be read-only files somewhere in the tree? If so, use filesystemobject.deletefolder "foldername",true - the true forces deletion of read-only files.

  9. #9
    Friez's Avatar
    Join Date
    Dec 2006
    Posts
    839
    Thank Post
    22
    Thanked 22 Times in 21 Posts
    Rep Power
    23

    Re: FileSystemObject Folder why permission denied

    Manage to fix your problem? I've been a bit slow to spot this thread!

    Dunno about VBS, but I've coded C++ apps in .net that bring up this error. It happens if you try to access things across UNC/mapped drives (.net has a pile of BS 'security' additions that prevent code being executed in this way unless you 'appease' the security -- what nonsense!).

    If you're running it off a network, try copying it to a local machine, failing that check if its trying to do network file access.

  10. #10

    Join Date
    Feb 2006
    Posts
    1,187
    Thank Post
    0
    Thanked 1 Time in 1 Post
    Rep Power
    0

    Re: FileSystemObject Folder why permission denied

    @srochford

    The force parameter worked but what I don't understand is why the same error comes up when you're just trying to find the folder size.

    Read-only file blocking a recurisive delete but why what kind blocks directory sizing when you have admin priviliges.

    @Friez
    Code C++ in .net? You bad boy. You don't believe Microsoft that C# is speedy enough for everybody.

  11. #11
    Friez's Avatar
    Join Date
    Dec 2006
    Posts
    839
    Thank Post
    22
    Thanked 22 Times in 21 Posts
    Rep Power
    23

    Re: FileSystemObject Folder why permission denied

    I've never learned C# as such. I've always coded in C++ mainly due to coding for mac, linux and windows (impossible in C#) but now and then I have to code for Windows specific thing.

    I code games as a hobby, C# is FAR too clunky for serious development in that area.

  12. #12

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,156
    Thank Post
    116
    Thanked 529 Times in 452 Posts
    Blog Entries
    2
    Rep Power
    124

    Re: FileSystemObject Folder why permission denied

    Quote Originally Posted by NetworkGeezer
    @srochford

    The force parameter worked but what I don't understand is why the same error comes up when you're just trying to find the folder size.

    Read-only file blocking a recurisive delete but why what kind blocks directory sizing when you have admin priviliges.
    If there are any sub-folders which you don't have permission to access (because the permissions are wrong) then this will fail.

    I'm not absolutely sure why this is but I'd guess the logic is this: when you want to know the size of a folder the OS has to open that folder to see what's inside it. If you're not allowed to open that folder then you won't be able to get the size of it and the only sensible message to return is "access denied" - because that's what it is!

    Are these user home folders? If so, I'd guess a user has created a folder and then changed the permissions so that only they have rights. This might be for badness or just because they're experimenting :-)

    What I'd guess you need to do is make sure that you have rights to every folder in the tree before you try to find the size of the folders.

  13. #13

    Join Date
    Feb 2006
    Posts
    1,187
    Thank Post
    0
    Thanked 1 Time in 1 Post
    Rep Power
    0

    Re: FileSystemObject Folder why permission denied

    Alright this isn't making any sense. The trouble seems to come if I try to For Each (iterate) through a subfolders collection. I get "Permission Denied" when trying to get folder size of each constituent folder.

    But if I use a FOR /F to get the folders and then call the VBS script using the folder name as an argument, the Folder.Size call works.

    This has been the problem all along. My access rights are OK using command line or batch script to do the task but not VBS

    I am the domain admin for pity's sake. Gimme the blasted information you blasted annoying script engine.

  14. #14

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,763
    Thank Post
    3,273
    Thanked 1,053 Times in 974 Posts
    Rep Power
    365

    Re: FileSystemObject Folder why permission denied

    any chance you can post the script along with the error or better yet a screen shot of the error the script gives you

  15. #15

    Join Date
    Feb 2006
    Posts
    1,187
    Thank Post
    0
    Thanked 1 Time in 1 Post
    Rep Power
    0

    Re: FileSystemObject Folder why permission denied

    Code:
    objFSO = CreateObject("Scripting.FileSystemObject")
    objHomeRoot = objFSO.GetFolder("E:\\Student\\HomeFolders\Year" & WScript.Arguments(0))
    
    For Each objSubFolder In objHomeRoot.SubFolders
    
          WScript.Echo "Folder " & objSubFolder.Name & " occupies " & objSubFolder.size & " bytes"
    
    Next
    I get the permission denied error at the WScript.Echo line unless I either delete or comment out the objSubfolder.size term.

    I have also tried a test in JScript but with the same result "Permission Denied"

    Code:
    fso = new ActiveXObject("Scripting.FileSystemObject");
    f = fso.GetFolder("E:\\Student\\HomeFolders\\Year7");
    fc = new Enumerator(f.SubFolders) ;
    s = "" ;
       for (;!fc.atEnd(); fc.moveNext())
          {
              WScript.Echo(fc.fc.item().size);
             
          };

    But the it the .size member works if I do it outside a For Each loop. Now as there is no way of refering to the constituents of the SubFolders collection without knowing their names this means I have to feed the names using FOR /F command subsitution:

    Code:
     CD E:\Student\HomeFolders\Year7 & FOR /F %f in ('DIR /AD /B ') do cscript /NoLogo HomeSize.vbs  %f
    which calls

    Code:
    objFSO = CreateObject ("Scripting.FileSystemObject")
    objHomeFolder = objFSO.GetFolder(WScript.Arguments(0))
    WScript.Echo "Folder " & objHomeFolder.name & " consumes " & objHomeFolder.size
    This works but why not enumarating through a subfolders collection using For Each?

    Aaargh!!! What is going on????

SHARE:
+ Post New Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. Photostory Access denied error.
    By ICT_GUY in forum Windows
    Replies: 20
    Last Post: 10th February 2010, 11:03 AM
  2. adding folder security permission on all PCs
    By edie209 in forum Windows
    Replies: 7
    Last Post: 7th December 2007, 11:39 AM
  3. Folder Redirection and Permission problem
    By ArchersIT in forum Windows
    Replies: 8
    Last Post: 24th July 2007, 09:02 AM
  4. Permission set on redirected folder not applying (GPO issue)
    By projector1 in forum Wireless Networks
    Replies: 3
    Last Post: 14th February 2007, 12:46 PM
  5. Replies: 15
    Last Post: 12th October 2006, 09:37 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •