Windows Vista Forums

DeleteFolder access denied
  1. #1


    IdleBrain Guest

    DeleteFolder access denied

    Hello,
    As part of a VBScript, when I am trying to run the following line of
    code after using tempFolderLocation with Run(command), I get 'access
    denied' error.
    FSO.DeleteFolder tempFolderLocation, True
    However the above line removes all individual files within that
    folder.

    Using process explorer from SysInternals, I found that the Vbscript
    still has a file handle to tempFolderLocation. If I close the file
    handle to tempFolderLocation manually just before FSO.DeleteFolder
    executes, FSO.DeleteFolder runs fine without any error.

    I am interested in finding out how I can close the handle to
    tempFolderLocation before executing FSO.DeleteFolder.

    Thanks in advance.



      My System SpecsSystem Spec

  2. #2


    Pegasus [MVP] Guest

    Re: DeleteFolder access denied



    "IdleBrain" <indianmostwanted@newsgroup> wrote in message
    news:d57a1921-3b2e-4347-918d-806ec0faa4b3@newsgroup

    > Hello,
    > As part of a VBScript, when I am trying to run the following line of
    > code after using tempFolderLocation with Run(command), I get 'access
    > denied' error.
    > FSO.DeleteFolder tempFolderLocation, True
    > However the above line removes all individual files within that
    > folder.
    >
    > Using process explorer from SysInternals, I found that the Vbscript
    > still has a file handle to tempFolderLocation. If I close the file
    > handle to tempFolderLocation manually just before FSO.DeleteFolder
    > executes, FSO.DeleteFolder runs fine without any error.
    >
    > I am interested in finding out how I can close the handle to
    > tempFolderLocation before executing FSO.DeleteFolder.
    >
    > Thanks in advance.
    Does the problem occur when you run this 2-line fragment of your code?
    set fso=createobject("Scripting.FileSystemObject")
    FSO.DeleteFolder tempFolderLocation, True

    If it does not then the problem is caused by whatever code you excecute
    before this fragment. You need to post it in order to get a good answer.


      My System SpecsSystem Spec

  3. #3


    IdleBrain Guest

    Re: DeleteFolder access denied

    Yes, the problem occurs when I run: FSO.DeleteFolder
    tempFolderLocation,True

    I am not running any particular code from within the
    'tempFolderLocation' but I am running a batch file (.cmd) within that
    folder using run(command) and waiting until the batch file is
    completed.

    Even a sleep of 30s does not help with not getting 'access denied'
    error message.

      My System SpecsSystem Spec

  4. #4


    Pegasus [MVP] Guest

    Re: DeleteFolder access denied



    "IdleBrain" <indianmostwanted@newsgroup> wrote in message
    news:f32c3b35-234d-42d0-9545-a40512b2a457@newsgroup

    > Yes, the problem occurs when I run: FSO.DeleteFolder
    > tempFolderLocation,True
    >
    > I am not running any particular code from within the
    > 'tempFolderLocation' but I am running a batch file (.cmd) within that
    > folder using run(command) and waiting until the batch file is
    > completed.
    >
    > Even a sleep of 30s does not help with not getting 'access denied'
    > error message.
    Your answer is a little ambiguous and we need to be very precise here. The
    questions is: Does the problem occur when you run this 2-line fragment of
    your code?

    set fso=createobject("Scripting.FileSystemObject")
    FSO.DeleteFolder tempFolderLocation, True

    In other words, does it occur when you paste these two lines into a .vbs
    file, replace tempFolderLocation with an actual string, then invoke the
    script?


      My System SpecsSystem Spec

  5. #5


    IdleBrain Guest

    Re: DeleteFolder access denied

    Sorry for misunderstanding your question..
    I can manually go and delete the folder without any error messages or
    can run a script with just those two lines of code and have no
    problem.


      My System SpecsSystem Spec

  6. #6


    Pegasus [MVP] Guest

    Re: DeleteFolder access denied



    "IdleBrain" <indianmostwanted@newsgroup> wrote in message
    news:b44fc9b3-cca1-4178-b2ad-96554a9e93f9@newsgroup

    > Sorry for misunderstanding your question..
    > I can manually go and delete the folder without any error messages or
    > can run a script with just those two lines of code and have no
    > problem.
    >
    This is what I suspected. Your problem is caused by one of the following:
    a) The code that you do not show us opens the folder you wish to delete, or
    a file inside this folder.
    b) Your current working directory is the folder you wish to delete.

    It is impossible to say which one it is unless you post the full VB Script
    code and how exactly you invoke it.


      My System SpecsSystem Spec

  7. #7


    IdleBrain Guest

    Re: DeleteFolder access denied

    The problem, like you suggested, was that the working directory was
    set to the tempFolderLocation.
    As soon as I changed the working directory after I am completed with
    the code execution in the tempFolderLocation, the deleteFolder method
    did not complain any more about 'Access Denied'!

    Appreciate your help and hats off for your insight into the problem.





      My System SpecsSystem Spec

DeleteFolder access denied problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
can't open access control editor. Access is denied pjjppj General Discussion 3 20 Oct 2008
Access Denied, Access Denied- like a broken record! Sam Vista General 7 25 Apr 2008
When standard users access Vista registry remotely, Access Denied Gayle Vista account administration 1 10 Oct 2007
Access Denied trying to access Vista PC Ron Vista networking & sharing 7 30 Sep 2007
Access is denied message when trying to access a remote printer MarkC Vista print fax & scan 1 08 Mar 2007