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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewIT / Software Engineering ConsultantCommented:
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
Bill PrewIT / Software Engineering ConsultantCommented:
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
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

LD16Author Commented:
Perfect, it works for me. Thank you Bill.
0
Bill PrewIT / Software Engineering ConsultantCommented:
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 PrewIT / Software Engineering ConsultantCommented:
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
Bill PrewIT / Software Engineering ConsultantCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.