Announcement

Collapse
No announcement yet.

Forcing deletion of folder with ReadOnly files.

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Forcing deletion of folder with ReadOnly files.

    Hello World

    I'm trying to complete this: I need to delete
    \documents & settings\username\local settings\temp
    folder at computer startup and I'm implementing this via GPO.

    My peice of code is:
    Code:
    set oFS = CreateObject("Scripting.FileSystemObject")
    set oWSH = CreateObject("WScript.Shell")
    
    'gets the last logged on user
    sLastUser = oWSH.RegRead ("HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultUserName")
    'set path
    sTempPath = "c:\Documents and Settings\" & sLastUser & "\Local Settings\Temp"
    
    'delete entire folder
    oFS.DeleteFolder(sTempPath)
    Everything works fine, except when inside TEMP folder there are Read-Only files.
    In that case I receive an Access Denied during computer startup.
    Is there a way to force deletion for RO files (or anso for locked files) so that deletion is surely completed?

    Thanks so much
    Luke and Max Hit the Road

  • #2
    Re: Forcing deletion of folder with ReadOnly files.

    In \temp\ you're also going to run into files that are in use and cannot be deleted.

    You need to build in some error trapping in your script to ignore error messages and continue. And accept the fact that you cannot delete all files from \temp\, in particular the files that are in use.

    Jas
    VCDX3 #34, VCDX4, VCDX5, VCAP4-DCA #14, VCAP4-DCD #35, VCAP5-DCD, VCPx4, vEXPERTx4, MCSEx3, MCSAx2, MCP, CCAx2, A+
    boche.net - VMware Virtualization Evangelist
    My advice has no warranties. Follow at your own risk.

    Comment


    • #3
      Re: Forcing deletion of folder with ReadOnly files.

      Originally posted by jasonboche
      In \temp\ you're also going to run into files that are in use and cannot be deleted.

      You need to build in some error trapping in your script to ignore error messages and continue. And accept the fact that you cannot delete all files from \temp\, in particular the files that are in use.

      Jas
      The script is deleting the ** TEMP FILES ** from a locally cached profile of the last user who logged on, not the current user so files shouldn't be in use unless the current user was the last user logged on.

      Try this...

      Code:
      set oFS = CreateObject("Scripting.FileSystemObject")
      set oWSH = CreateObject("WScript.Shell")
      
      'gets the last logged on user
      sLastUser = oWSH.RegRead ("HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultUserName")
      'set path
      sTempPath = "c:\Documents and Settings\" & sLastUser & "\Local Settings\Temp"
      
      'delete entire folder
      oFS.DeleteFolder(sTempPath),True
      Last edited by ahinson; 24th May 2006, 18:59.
      Andrew

      ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

      Comment


      • #4
        Re: Forcing deletion of folder with ReadOnly files.

        In that case, Microsoft UPHClean may also be needed. Improperly unloaded User Profile Registry Hives will leave open files which cannot be deleted.

        The UPHClean has become so commonplace to troubleshoot issues that I hear it is being included in the base code of Longhorn/Vista.

        Jas
        VCDX3 #34, VCDX4, VCDX5, VCAP4-DCA #14, VCAP4-DCD #35, VCAP5-DCD, VCPx4, vEXPERTx4, MCSEx3, MCSAx2, MCP, CCAx2, A+
        boche.net - VMware Virtualization Evangelist
        My advice has no warranties. Follow at your own risk.

        Comment


        • #5
          Re: Forcing deletion of folder with ReadOnly files.

          Originally posted by ahinson
          oFS.DeleteFolder(sTempPath),True
          Already tried
          Didn't work
          Luke and Max Hit the Road

          Comment


          • #6
            Re: Forcing deletion of folder with ReadOnly files.

            Originally posted by jasonboche
            In that case, Microsoft UPHClean may also be needed. Improperly unloaded User Profile Registry Hives will leave open files which cannot be deleted.
            Jas
            You missed the point
            I'm trying to delete only TEMP folder during computer startup (not entire profile, not during logon)
            Luke and Max Hit the Road

            Comment


            • #7
              Re: Forcing deletion of folder with ReadOnly files.

              Originally posted by lukeandmax
              You missed the point
              I'm trying to delete only TEMP folder during computer startup (not entire profile, not during logon)
              UPHClean does not strictly apply to the deletion of an entire user profile and I did not suggest you were deleting or should delete the entire user profile.

              One of the items that UPHClean addresses is the proper closing of hung open file handles (which in your case may be open file handles on the temp directory which is why I suggested the UPHClean utility).

              With that, I don't think I missed the point as you suggest.

              Good luck.

              Jas
              VCDX3 #34, VCDX4, VCDX5, VCAP4-DCA #14, VCAP4-DCD #35, VCAP5-DCD, VCPx4, vEXPERTx4, MCSEx3, MCSAx2, MCP, CCAx2, A+
              boche.net - VMware Virtualization Evangelist
              My advice has no warranties. Follow at your own risk.

              Comment


              • #8
                Re: Forcing deletion of folder with ReadOnly files.

                Originally posted by jasonboche
                UPHClean does not strictly apply to the deletion of an entire user profile and I did not suggest you were deleting or should delete the entire user profile.

                One of the items that UPHClean addresses is the proper closing of hung open file handles (which in your case may be open file handles on the temp directory which is why I suggested the UPHClean utility).

                Jas
                Sorry, probably I used wrong words. I meant: my need is delete that folder during STARTUP. I suppose during startup there are no files locked inside one user's account TEMP folder... just because that user had not logged on yet.
                My doubt was: is there a way to force deletion of read-only files (talking about read-only flag attritbute, not ntfs permissions)? I asked also for deleting locked files because, if I cannot find a way to delete RO files, I have to find an alternate way during user logon which may imply deleting locked files.

                Hope to be clear now
                Luke and Max Hit the Road

                Comment


                • #9
                  Re: Forcing deletion of folder with ReadOnly files.

                  Originally posted by lukeandmax
                  Already tried
                  Didn't work
                  If you look at the MS documentation for the vbscript filesystem object you'll see that what I submitted is the correct syntax to delete a folder with files that have the read-only file attribute set to true.

                  If it's not working the file may be in use or something else.

                  Originally posted by MSDN

                  Arguments

                  object
                  Required. Always the name of a FileSystemObject.

                  folderspec
                  Required. The name of the folder to delete. The folderspec can contain wildcard characters in the last path component.

                  force
                  Optional. Boolean value that is true if folders with the read-only attribute set are to be deleted; false (default) if they are not.

                  http://msdn.microsoft.com/library/en...1971d6c0d9.asp
                  Andrew

                  ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

                  Comment


                  • #10
                    Re: Forcing deletion of folder with ReadOnly files.

                    Originally posted by ahinson
                    If you look at the MS documentation for the vbscript filesystem object you'll see that what I submitted is the correct syntax to delete a folder with files that have the read-only file attribute set to true.

                    If it's not working the file may be in use or something else.
                    I know, and that's the reason why I told you I already tried.

                    So now the intresting fact is: how the hell do I know which process is locking a file inside one user's TEMP folder during computer startup????????

                    Maybe I have to try another solution..... for example renaming TEMP folder during startup, so at user logon TEMP is created empty once again. Meanwhile I can run some executable in background which try do delete the renamed temp....
                    If you have any idea, you're welcome to suggest !!
                    Last edited by lukeandmax; 26th May 2006, 07:54.
                    Luke and Max Hit the Road

                    Comment

                    Working...
                    X