Link to home
Start Free TrialLog in
Avatar of KentuckyDataService
KentuckyDataServiceFlag for United States of America

asked on

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.
Avatar of zelron22
zelron22

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.
Avatar of KentuckyDataService

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of zelron22
zelron22

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Just an FYI, just because something has a file handle that locks a file, don't assume it's locked by explorer.
Thanks for the help.  I used part of your answer as the solution to keep them from creating the extra profiles.