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

Batch Kill / Delete a file locked by Explorer.exe

I am writing a script that searches and deletes all profiles out of the C:\Documents and Settings\ folder on all our citrix farm servers.  Here is the basic module breakdown of the script:
1.  Get input folder name
2.  xcacls to remove all inherited permissions / write new permissions (just to make sure...probably not necessary)
3.  Unlock files **
4.  Delete Files
5.  Write to log for verification.


Now, i have found 1 other script that make this work...1 that runs the search / delete / export log.

The problem is...there are some *.tmp files that are locked by explorer.exe that i can not get deleted.  If i use a program like...unlocker.exe, it can delete them, but i cannot get the command line unlock to work with that program.  So, i am needing a way to unlock all files in a folder that i can vbs script call / use.

Thanks in advance for your help.
0
KentuckyDataService
Asked:
KentuckyDataService
  • 2
  • 2
1 Solution
 
zelron22Commented:
Are the users still logged on?  Log them off first, then run this.  

That being said, what are you trying to accomplish?  There may be an easier solution.
0
 
KentuckyDataServiceAuthor Commented:
No, all users are logged off.  We are trying to clear out the docs & settings folder.  Cause when a profile gets messed up, it creates a new one..ie TEMP, TEMP.000, TEMP.001....

We are just trying to keep that folder cleared...but that UTIL i wrote can't work because a few files are Locked by explorer.exe; though no one is logged in.  We are checking tonight to see if there still is an instance of explorer.exe running....because with no one logged in..there shouldn't be.
0
 
zelron22Commented:
Have you installed UPHClean?  Also, you can set local profiles to be deleted at log off using group policy.  It sounds like either people are disconnecting instead of logging off (and you can force log off) or that an application is hanging when they log off keeping them from really logging off.

Anything in the event log about hung applications?
0
 
Justin_W_ChandlerCommented:
Just an FYI, just because something has a file handle that locks a file, don't assume it's locked by explorer.
0
 
KentuckyDataServiceAuthor Commented:
Thanks for the help.  I used part of your answer as the solution to keep them from creating the extra profiles.
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

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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