How to unlock locked files?

Windows specific forum
User avatar
newtheogott
Enthusiast
Enthusiast
Posts: 120
Joined: Sat Apr 26, 2003 2:52 pm
Location: Germany, Karlsruhe
Contact:

How to unlock locked files?

Post by newtheogott »

I've just found an intresting freeware-tool. UNLOCKER.
http://ccollomb.free.fr/unlocker/

A file is LOCKED.

Locked means, Windows permits you to kill it because it assumes that this file is "in use".

The Tool Unlocker can:
- find out which EXE or DLL has locked the file
- UNLOCK the file WITHOUT killing this exe.

MY simple question is: WHCIH API is used for such contructs.
HOW can I:
- Find out WHO has locked a file?
- Unlock the file (even without killing the locking process/DLL)?


See more on what other Tool can also do this and about unlocker here: http://ccollomb.free.fr/unlocker/
--Theo Gottwald
-----------------------------------------
http://www.it-berater.org * http://www.fa2.de * http://www.smart-package.com
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

http://ollydbg.de/

Can list api's too.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: How to unlock locked files?

Post by PB »

Files are locked for a reason. Unlocking them is not recommended if you
value their contents. You should only unlock a file if you don't need it, but
doing so may cause system instability as a result.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
newtheogott
Enthusiast
Enthusiast
Posts: 120
Joined: Sat Apr 26, 2003 2:52 pm
Location: Germany, Karlsruhe
Contact:

Post by newtheogott »

Thanks for the information, however I would primarily be intrested, if someone knows HOW TO:
a) find out, Which programm has a "LOCK" on a file
b) HOW you can remove the lock without killing the file.

Does anyone know that?

Now to the point, "what its good for". Let me show you a number of tools that make use of this mechanism, so you see - its a commonly used knowledge -. Doesn't mean I want unlock all files on my Computer for fun. I just want to know how i could unlock files if needed.

Following is from the unlocker-web site:

****************************

Similar programs and why Unlocker is better

Of course I only compare here the unlocking feature. Process Explorer and Take Control are very good programs featuring much more things than just unlocking folders. The main goal of this list is not really to pretend Unlocker is better but also to provide a list of all comparable programs so that if you have a problem with Unlocker you can try alternatives which might fit better your needs. If you have enough time I really recommend testing those products so that to make your own mind.

Process Explorer by Sysinternals is a fabulous freeware tool. However you need to open it and type the name of your file so that so search for lockers. Then you need to right click every handle and close them one after another, since there is no multi-selection. Process explorer can not unload DLLs. Unlocker allows you to right click the file or folder directly in explorer and close all handles all at once. Unlocker since 1.6 can unload DLLs.

WhoLockMe by Dr-Hoiby is a very good freeware tool and has inspired Unlocker in many ways. However WhoLockMe only proposes to kill processes and not close the handle which is annoying and what pushed me to create Unlocker. Wholockme can not unload DLLs. Unlocker allows you to close handles and keep processes alive, which is nice especially when Explorer.exe is open and you don't want to lose all your windows. Unlocker since 1.6 can unload DLLs.

FreeFile by Skrubbeltrang is another freeware tool. The very bad point is that it requires the .Net Framework to be installed. The second is that it can only kill processes. FreeFile can not unload DLLs. Unlocker is light and do not need MFC or .Net to close handles and keep processes alive. Unlocker since 1.6 can unload DLLs.

Take Control by Computers In Motion is a very good shareware tool. First it is not free, secondly you need to enter the file name, and finally as FreeFile and WhoLockMe it can only kill processes, however the nice thing is it restarts Explore.exe automatically after it is closed. Take Control can not unload DLLs. Unlocker is free, features an explorer extension and only close handles and keeps processes alive. Unlocker since 1.6 can unload DLLs.

Pocket KillBox by Option^Explicit is a freeware tool. However I consider it the worst of the lot since it only adds file to a list, which will be deleted only the next time you reboot your computer. KillBox can not unload DLLs. Unlocker allows you to delete files and folder instantly without rebooting your computer. Unlocker since 1.6 can unload DLLs.

ForceDel by Zoltan Csizmadia is a freeware command line tool. According to the source code it seems to do its job reasonably well, but will miss certain processes and handles than unlocker will find. ForceDel can not delete DLLs loaded by processes. Since 1.5.1 Unlocker can also be used as a command line with the silent mode, and has the clear advantage to be accessible to everyone with the explorer extension and the graphical interface. Unlocker since 1.6 can unload DLLs. Thanks to Bert van Velsen for the tip.

Locked Files Wizard / Copylock by Noel Danjou is a freeware tool both available with an Explorer extension or a command line. However the program is not very efficient without rebooting, since it failed in the most simple cases I tried. Moreover the interface as a wizard is not very direct and quick to use. When it fails it will act as Killbox do and log the files to be deleted during the next reboot. Unlocker can unlock files and folders immediately without rebooting.

Advanced Process Manipulation by DiamondCS is a freeware tool that allows you to unload DLLs loaded by any process in the system. However you need to find which process locks a DLL and since there are several processes and most link many DLLs the search is not very convenient. Unlocker since 1.6 can also unlock DLLs loaded by other processes and the locks can be very simply found by right cliking on the file itself with the Explorer extension. Moreover Unlocker can also unlock files and folders and not only DLLs.

DLL Master by Tony Shaftel is a shareware tool that allows you to unload 16-Bit DLLs loaded by any process in the system. First it needs VB DLLs to be installed to run, secondly it does not support module loading and unloading from 32-bit process address (most DLLs these days are loaded from 32-bit processes), and at last you have to search DLLs in a list which is not very convenient. Unlocker is free, does not need VB DLLs to run, can unload DLLs from any process and has an Explorer extension. Unlocker can also unlock files and folders and not only DLLs.
--Theo Gottwald
-----------------------------------------
http://www.it-berater.org * http://www.fa2.de * http://www.smart-package.com
Armoured
Enthusiast
Enthusiast
Posts: 365
Joined: Mon Jan 26, 2004 11:39 am
Location: ITALY
Contact:

Post by Armoured »

Hi :)
You can show to me an example of an unlock procedure? :?





Thanks.
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

newtheogott wrote:Thanks for the information, however I would primarily be intrested, if someone knows HOW TO:
a) find out, Which programm has a "LOCK" on a file
Maybe you are looking for this :
http://www.sysinternals.com/Utilities/Handle.html
Ever wondered which program has a particular file or directory open? Now you can find out. Handle is a utility that displays information about open handles for any process in the system. You can use it to see the programs that have a file open, or to see the object types and names of all the handles of a program.
You can also get a GUI-based version of this program, Process Explorer.
http://www.sysinternals.com/Utilities/P ... lorer.html
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
Armoured
Enthusiast
Enthusiast
Posts: 365
Joined: Mon Jan 26, 2004 11:39 am
Location: ITALY
Contact:

Post by Armoured »

Hi :)
Ok but these are programs.
There is any one with a concrete example about how to unlock a file? :?



Thanks
chris319
Enthusiast
Enthusiast
Posts: 782
Joined: Mon Oct 24, 2005 1:05 pm

Post by chris319 »

This is an interesting topic. I have two commercial applications which I suspect are not properly unlocking files when they shut down, making those files unavailable to PB.
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

Somewhat interesting, but aside from the reply asking if there might be some way to unlock in PB, shouldn't this be "off topic", possibly added to the tools list if any of them are freeware?

cheers,
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

unless we add code, yes :-)

you can lock a file from within a process, but you cannot unlock the file from another process, at least i did not find an easy way to do that :-)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Dr. Dri
Enthusiast
Enthusiast
Posts: 243
Joined: Sat Aug 23, 2003 6:45 pm

Post by Dr. Dri »

blueznl wrote:unless we add code, yes :-)

you can lock a file from within a process, but you cannot unlock the file from another process, at least i did not find an easy way to do that :-)
Can you share your code ? I don't care if it's not a PB code but i would like to know how to do that for my program's process

Dri :)
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

do a search for 'lockfile' in the win32.hlp file, it's a winapi call
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Dr. Dri
Enthusiast
Enthusiast
Posts: 243
Joined: Sat Aug 23, 2003 6:45 pm

Post by Dr. Dri »

I don't know how to use unlockfile and unlockfileex... It seems that it only unlock files locked with lockfile or lockfileex

Dri :oops:
User avatar
Michael Vogel
Addict
Addict
Posts: 2821
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

Had anyone success in doing a unlock with PB?

I need it for an aborted filecopy command, how to get the handle from it for the API functions?
Otherwise, when aborting the copying, the actual file can't be deleted, overwritten, etc. until the program quits.

Code: Select all

Procedure CopyList(Nothing.l)
Protected i.l=-1
While i<totalfiles
  i+1
  source=SourceList(i)
  dest=DestList(i)
  if CopyFile(source,destpath)=0
    error=99
    break
  endif
wend
endpocedure

ThreadID=CreateThread(@CopyList(),0)

; if Abort-Button... KillThread(ThreadID)
dell_jockey
Enthusiast
Enthusiast
Posts: 767
Joined: Sat Jan 24, 2004 6:56 pm

Post by dell_jockey »

in one instance I've had a very persistent locking problem. Even rebooting didn't resolve the issue.

As it transpired, explorer.exe was locking it, independent from the security credentials of the user account. I couldn't delete the file as a normal user, not as an admin, not even when starting another explorer with system credentials.

What solved it was:

- use the Windows task manager to kill the explorer.exe process (all your desktop icons will vanish...)
- then use the Task Manager to start a new task. I started CMD.EXE
- within CMD.EXE, I was able to delete the file I couldn't delete before.
- then I again used Task Manager to start a new task, this time to restart explorer.exe (your desktop will be restored)

Perhaps this description might help someone, some day...
cheers,
dell_jockey
________
http://blog.forex-trading-ideas.com
Post Reply