File locked which process




















Problem solved! What to do when there are no active applications that seems to be locking that file? The software is also freeware and it gets the job done just like the former one.

The tool also features a powerful search capability that will quickly show you which processes have particular handles opened or DLLs loaded.

This will allow us to use it to easily fix most unwanted file locks in a matter of seconds: we just have to search for the locked file, retrieve the process which is keeping the handle and close or kill it accordingly. In order to achieve such surgical result we need to get our hands to another great Sysinternals utility that goes by the name of Handle.

Handle is basically the console version of ProcessExplorer : think of it like a ProcessExplorer with command-line options instead of the GUI. This could make it less intuitive when we need to investigate our system, yet it has extremely powerful tools when it comes to fix the issues we found. If everything goes correctly, you will fix your problem without killing the process and — more importantly — without having to reboot the system.

October 22, October 22, June 12, June 12, June 11, Since it's also a lead designer for many App and games for Android, iOS and Windows Phone mobile devices for a number of italian companies. Hi I just wanted to say, that I have used both the unlockers mentioned, and that it seems odd that you write the following:. IObit Unlocker is freeware without any bloatware. Threading; using Microsoft.

SafeHandles; namespace Crmc. CloseHandle base. WillNotCorruptState, Cer. Success ] [DllImport "kernel GetOpenFilesEnumerator p. Zero; RuntimeHelpers.

IEnumerator System. OpenProcess ProcessAccessRights. DuplicateHandle processHandle. FileName; return f. Handle, out fileName ; s. ObjectTypeInformation, IntPtr.

TryGetValue devicePath. Concat drive, devicePath. Substring i ; return dosPath. Substring 0, 2 ; NativeMethods. Add networkDevicePrefix. Substring 0, networkDevicePrefix. Length, StringComparison. Substring deviceName. Arsen Zahray Boog Boog 3, 4 4 gold badges 27 27 silver badges 23 23 bronze badges. This code appears to show all files opened by a given process but the OP is asking for quite the opposite. I've tested this code and Ians code, and I must say that I like the results of this code much better.

No idea why someone would downgrade this answer — Arsen Zahray. Show 1 more comment. Michael Michael Thanks for this. Here's also a good article on the Restart Manager topic: msdn. Detailed here is a method for getting processes that use a file. This really should be the accepted answer. It's the only solution that doesn't use 3rd party tools or undocumented APIs. What error codes are returned? Seeing that the Restart Manager API is primarily used with installers, and there's no issue running installers from a service, I would be surprised to find out, that the Restart Manager wouldn't work from a service.

What I mean is that you can't use the API from a c windows service application. That won't work. But of course you can start a separate desktop executable from the service. That might work. You could run it, and parse the result. Daniel Silveira Daniel Silveira Not sure running a 3rd party tool and parsing output counts as "programatically". Daniel You need to have it installed, have administrative privileges and rely on the user interface output.

Can't think of a less elegant solution let alone a 'programmatical' one. Sometimes integrating a third party tool is necessary. It saves the effort of trying to rewrite code that someone else has already written. You can easily package up the exe with your own deployment package. I wouldn't consider it a 3rd app, since it is provided by Microsoft Itself.

Anyway, do you have a better approach? It's ok to use any valid solution you might see easy. I prefer to stick with. NET Framework defaults. Show 3 more comments. So, with that disclaimer, here is the code to retrieve handles which has been adapted to work apart from the occasional lock-up both in 32 and 64 bit modes: using System; using System. Linq; using System. WriteLine "Enumerates open handles. Name from time to time. Abort won't help. File Console. AllocHGlobal length ; if NativeMethods.

ObjectTypeInformation, ptr, length, out length! ObjectNameInformation, IntPtr. ObjectNameInformation, ptr, length, out length!

However, it may occur that a file or a library is used by an unknown or system process. Then it is harder to unlock it. A file lock message may be different. For example, the following screenshot shows the file type and the app it is associated with :. However, sometimes you may see a more interesting message that a file is used by an unknown or Windows system process. It may be either a Windows process or other processes working with the System privileges, like an antivirus app, a backup agent, an MSSQL database, etc.

The easiest way to unlock the file is to end the process that has locked it. But it is not always possible, especially on the servers. The process and its child processes access the file using the handler. Using Windows API, you can send a signal to your file system to free the file handle and unlock the file. So you have closed the file handle without ending the parent process.

Then you can remove or rename the file. It allows you to find a process having locked your file and release the lock by freeing the handle.



0コメント

  • 1000 / 1000