When Delphi cannot output the .exe file because it is locked
Posted by jpluimers on 2025/08/20
Sometimes Delphi cannot output the .exe file because it is locked. In even rarer times, Delphi itself keeps the .exe file locked (this has done it for decades and I think this is caused by a bug in the debugger).
A long time ago, I answered how to figure out where the lock comes from. A decade later a comment was added (thanks [Wayback/Archive] Server Overflow) with a command-line tool you can use for that too (but sometimes returns less results). Both are in [Wayback/Archive] compilation – Delphi does not generate any exe file – Stack Overflow
A
Run Process Explorer, search for any open handles to
C:\test\Project1.exeusing Find, Find handle or dll.That will tell you what is locking your .exe.
C
There is another tool from Mark R, called “handle”. It also shows all open handles. learn.microsoft.com/en-us/sysinternals/downloads/handle
The pages I had linked to have since then long gone. The second page does not even redirect (link rot), but I found out it has moved and updated since and now includes the handle.exe solution (also by SysInternals) now as well and adds a new solutions.
So below are the links, including archived forms.
Note however that procexp.exe (Process Explorer) can find more handles than either resmon.exe or handle.exe, for instance the BCD can only be found using Process Explorer, and some cmd.exe matches are only returned by Process Explorer which I documented in this [Wayback/Archive] Thread by @jpluimers on Thread Reader App:
Wondering why
procexp.exesees more handles thanhandle.exeBoth run from the same elevated user.
Even running as
LocalSystem,handle.exedoes not see all handles thatprocexp.exesees.
Handle.exe does support the backslash while searching as for \cmd.exe it does see entries, but still far less than ProcExp.exe does
–
handle.exe: learn.microsoft.com/en-us/sysinternals/downloads/handle
–procexp.exe: learn.microsoft.com/en-us/sysinternals/downloads/process-explorer@markrussinovich any idea why this happens?
![]()
- [Wayback/Archive] Process Explorer redirects to [Wayback/Archive] Process Explorer – Sysinternals | Microsoft Learn
- [Wayback/Archive] Know which process has locked a file has died and moved to[Wayback/Archive] How to Identify the Process that has Locked a File in Windows and added solutions based on
resmon.exe(built-in), handle.exe (SysInternals),OpenFiles.exe(built-in, but requires a global flag to be enabled which for enabling requires a reboot). - [Wayback/Archive] Handle – Sysinternals | Microsoft Learn
usage:handle [[-a [-l]] [-v|-vt] [-u] | [-c <handle> [-y]] | [-s]] [-p <process>|<pid>] [name]Parameter Description -a Dump information about all types of handles, not just those that refer to files. Other types include ports, Registry keys, synchronization primitives, threads, and processes. -l Just show pagefile-backed section handles. -c Closes the specified handle (interpreted as a hexadecimal number). You must specify the process by its PID.
WARNING: Closing handles can cause application or system instability.-g Print granted access. -y Don’t prompt for close handle confirmation. -s Print count of each type of handle open. -u Show the owning user name when searching for handles. -v CSV output with comma delimiter. -vt CSV output with tab delimiter. -p Instead of examining all the handles in the system, this parameter narrows Handle’s scan to those processes that begin with the name process. Thus:
handle -p exp
would dump the open files for all processes that start with “exp”, which would include Explorer.name This parameter is present so that you can direct Handle to search for references to an object with a particular name.
For example, if you wanted to know which process (if any) has “c:\windows\system32” open you could type:
handle windows\system
The name match is case-insensitive and the fragment specified can be anywhere in the paths you are interested in.Handle Output
When not in search mode (enabled by specifying a name fragment as a parameter), Handle divides its output into sections for each process it is printing handle information for. Dashed lines are used as a separator, immediately below which you will see the process name and its process id (PID). Beneath the process name are listed handle values (in hexadecimal), the type of object the handle is associated with, and the name of the object if it has one.When in search mode, Handle prints the process names and id’s are listed on the left side and the names of the objects that had a match are on the right.
–jeroen
- [Wayback/Archive] Jeroen Wiert Pluimers @wiert@mastodon.social on Twitter: “Wondering why procexp.exe sees more handles than handle.exe Both run from the same elevated user. Even running as LocalSystem, handle.exe does not see all handles that procexp.exe sees.”
- [Wayback/Archive] Jeroen Wiert Pluimers @wiert@mastodon.social on Twitter: “Handle.exe does support the backslash while searching as for \cmd.exe it does see entries, but still far less than ProcExp.exe does – handle.exe: … – procexp.exe: … @markrussinovich any idea why this happens?”
- [Wayback/Archive] Jeroen Wiert Pluimers @wiert@mastodon.social on Twitter: “Oh, `resmon.exe` shows the same entries as `handle.exe`. “
- [Wayback/Archive] Jeroen Wiert Pluimers @wiert@mastodon.social on Twitter: “Forgot this one from `resmon.exe`: searching for `System32\cmd.exe` returns none.”












Leave a comment