VBscript & Batch file: remove & break lock of a file

Hello Experts,

I would like to launch a cmd or a vbscript in order to break or remove lock in a file
Example. I want to remove a csv file and I am not able to remove it because it is used by another user.
I would like to break the lock in order to be able to remove file.

How should I proceed?

Thank you very much for your help.
LVL 1
LD16Asked:
Who is Participating?
 
Bill PrewCommented:
Well, I would say you need to test it under your specific circumstances.  Create a test where you leave a file locked as you mention, and then try to unlock it.  See if it works, and if there are any negative effects.

I would try Nirsoft utility, they have good products.


»bp
0
 
Bill PrewCommented:
Hello LD11,

Are third party utilities in play, or does this have to be pure BAT, VBS, PS1?


»bp
0
 
LD16Author Commented:
Hello Bill,

If we going through with bat or vbs it would be great. I want to avoid installing a third party utility.

Thank you very much for your help.
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
Bill PrewCommented:
Well, most of the tools I am thinking of don't require an install, just have to have the supporting EXE available to the BAT file...


»bp
0
 
LD16Author Commented:
Perfect, it works for me. Thank you Bill.
0
 
Bill PrewCommented:
Well, depending on why the file is locked, some of these may work better than others.  I would try in order presented, NirSoft always a goto for utils for me.

Naturally be aware that deleting a file that is locked can result in corruption, or worse...



»bp
0
 
LD16Author Commented:
Thank you very much. If you want just  to remove the lock and avoid corruption and negative effect which of the proposed solution is the best?

Thank you very much for your help.
0
 
Bill PrewCommented:
I'd probably go with NirSoft.  ForceDel is only for deletions.  And unlocker is popular, and I have used it in the past, when a portable version was more easily had, but they have come under fire a couple of times for adware, etc.

This feels like a fairly specific mission you are on, what type of files / applications are involved.  As I recall having tried this a time or two in the past on Office files, even after using a utility that "freed the lock" the files sometimes aren't able to be deleted or replaced.  Good old Microsoft knows how to lock things.  In addition, some MS (and other apps) will have a temporary file with the base file name and a funny extension while it is open.  Deleting the primary file won't remove that.


»bp
0
 
LD16Author Commented:
Hello Bill,

Thank you very much for your comment.
Files involved are csv files which are in a share directory server. Users sometimes forget to close files and this cause some issues when it comes to update new version of csv files.

Based on your comment, force delete of a lock file is a complex process not very well managed in MS. However what about just to clear the lock of the file withtout removing it? is this process straight forward to manage in MS?
Concerning your recommendation, the best option for just clear lock of a file will be which of the one's reported in your comment?
https://www.experts-exchange.com/questions/29086504/VBscript-Batch-file-remove-break-lock-of-a-file.html?anchor=a42484203&notificationFollowed=204544052#a42484141

Thank y ou very much for your help.
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.

All Courses

From novice to tech pro — start learning today.