• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2929
  • Last Modified:

Help with objfso.deletefolder getting access denied?

I've got a script that goes through and deletes a folder automatically based on criteria.  The entire script works except on some profiles I get "access denied" or "path not found", when indeed the path exists.

I even added an xcacls command to force permissions on the folder I'm deleting and I have full control, but still, access denied.

Is there a way I can see what process is hanging onto this folder?
0
piattnd
Asked:
piattnd
1 Solution
 
sirbountyCommented:
Is it likely that the full path exceeds the 250 character limit?
What if you map to a deeper folder path?  (i.e. net use t: \\%computername%\c$\docume~1\profile\foldera\folderb\folderc)
Can you manually delete it?
0
 
RobSampsonCommented:
^^^ If sirbounty is right, you could try the following.

Assume that strFolderPath holds something like
strFolderPath = "C:\Documents and Settings\username\Local Settings\Application Data\My Program"

you could then try getting the ShortPath of that
If objFSO.FolderExists(strFolderPath) = True Then
     objFSO.DeleteFolder objFSO.GetFolder(strFolderPath).ShortPath, True
Else
     MsgBox strFolderPath & " does not exist."
End If

But yeah, can you manually delete it?

Regards,

Rob.
0
 
piattndAuthor Commented:
Yes I can manually delete it.

As for mapping it as a drive, that I'm not sure.  I don't think it's exceeding the 250 character limit, as it's "\\XXXX-XXXX####\Documents and Settings\longuser.namelong" (that's about our longest naming convention for the folders I'm deleting).

I am deleting profiles, so I'm curious if installing UPHClean on the machines will do anything for me...
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
RobSampsonCommented:
I wouldn't think so.  You obviously won't be able to delete a profile that is currently logged on, and sometimes, something from another profile can be held onto, if that user has logged off, but not restarted since then next person logged on.

Regards,

Rob.
0
 
piattndAuthor Commented:
The script I'm running only deletes profiles that haven't been used in over 45 days.
0
 
piattndAuthor Commented:
And incase you're wondering about the synatx, here it is:

objFSO.DeleteFolder(strDeletePath),TRUE
0
 
piattndAuthor Commented:
What would cause a folder to be physically on the computer, but when trying to delete the folder, it says path cannot be found?
0
 
ChizlCommented:
If an application is using that folder or you have the folder open on that machine, I've seen the same error and will not let me delete it.
0
 
piattndAuthor Commented:
Right, but I've rebooted the machine and I still get the same error (even before anyone logs in).

I thought it might be because the read only attribute was showing flagged, but I can't clear it.  I can manually delete it, which boggles my mind......
0
 
RobSampsonCommented:
Hi, first off, I'm not sure this is correct...
objFSO.DeleteFolder(strDeletePath),TRUE

it should be

objFSO.DeleteFolder strDeletePath, True
or
objFSO.DeleteFolder(strDeletePath, True)

although with the second, you might get "cannot use parenthesis when calling a sub".

Secondly, what if you try:

If objFSO.FolderExists(strDeletePath) = True Then
     WScript.Echo strDeletePath & " exists. Attempting to delete..."
     objFSO.DeleteFolder strDeletePath, True
Else
     WScript.Echo strDeletePath & " does not exist."
End If

Thirdly....are you mapping a drive to the root of the folder you're trying to delete? Eg, are you mapping a drive to
\\computer\c$\documents and settings\username
and then trying to delete that folder?

That would probably give you permission denied because your computer has a network connection open to that path.

As a different alternative, you could try the following:

Set objShell = CreateObject("WScript.Shell")
strCommand = "cmd /k rd /s /q """ & strDeletePath & """"
objShell.Run strCommand, 1, True

and if that works, change the /k to /c to have the box disappear.

Regards,

Rob.
0
 
piattndAuthor Commented:
Thanks Rob.

I'm not mapping to the user's folder and then trying to delete it.  The method I'm using works for some and doesn't work for others.  I've tried to use UPHClean to clear the access denied issues, but still has a problem.  I'll try with the command prompt and see if that works.
0
 
piattndAuthor Commented:
An update on this, I tried the delete by command "rd" and I got "the file NTUSER.DAT and NTUSER.DAT.LOG are in use by another process.

I think a portion of my script might be locking some of the profiles up.  I'm still investigating, but atleast I know it's not a bug in the objfso.deletefolder comand.

Thank you all for your help!
0
 
RobSampsonCommented:
Yeah, those two files are the ones that usually get held open when a profile is loaded....

There's probably some third party tool out there to delete a file no matter what, which you could try to use for those two...

Regards,

Rob.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now