?
Solved

Help with objfso.deletefolder getting access denied?

Posted on 2008-11-06
13
Medium Priority
?
2,876 Views
Last Modified: 2012-05-05
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
Comment
Question by:piattnd
13 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 22898800
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
 
LVL 65

Expert Comment

by:RobSampson
ID: 22899340
^^^ 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
 
LVL 12

Author Comment

by:piattnd
ID: 22899381
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 65

Expert Comment

by:RobSampson
ID: 22899438
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
 
LVL 12

Author Comment

by:piattnd
ID: 22899518
The script I'm running only deletes profiles that haven't been used in over 45 days.
0
 
LVL 12

Author Comment

by:piattnd
ID: 22899669
And incase you're wondering about the synatx, here it is:

objFSO.DeleteFolder(strDeletePath),TRUE
0
 
LVL 12

Author Comment

by:piattnd
ID: 22900405
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
 
LVL 4

Expert Comment

by:Chizl
ID: 22900526
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
 
LVL 12

Author Comment

by:piattnd
ID: 22900658
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
 
LVL 65

Accepted Solution

by:
RobSampson earned 2000 total points
ID: 22900868
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
 
LVL 12

Author Comment

by:piattnd
ID: 22901038
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
 
LVL 12

Author Comment

by:piattnd
ID: 22918230
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
 
LVL 65

Expert Comment

by:RobSampson
ID: 22918296
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

831 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