# Unblock and Delete files that have been locked by Java

**URL:** <https://forum.inductiveautomation.com/t/unblock-and-delete-files-that-have-been-locked-by-java/60194>\
**Category:** General Discussion\
**Created:** [May 31, 2022, 6:45am UTC](https://forum.inductiveautomation.com/t/unblock-and-delete-files-that-have-been-locked-by-java/60194 "2022-05-31T06:45:33Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [May 31, 2022, 6:45am UTC](https://forum.inductiveautomation.com/t/unblock-and-delete-files-that-have-been-locked-by-java/60194/1 "2022-05-31T06:45:33Z")

</div>

There is an issue with java locking files that are in use. Mainly when using the webserver.  
Causing it to be impossible to delete them while the gateway is running.

But here is a solution! (For windows atleast). Using handle you can find and unlock files.

> **[Handle - Windows Sysinternals](https://docs.microsoft.com/en-us/sysinternals/downloads/handle)**
>
> This handy command-line utility will show you what files are open by which processes, and much more.

I made it a bit easier to use by writing a simple bat file.  
[UnlockAndDelete.zip](https://forum.inductiveautomation.com/uploads/short-url/7eEcAE6JGpz4JvjlyqUCP4CCD1X.zip) (891.3 KB)

Unzip on the pc in the gateway (in for example C:\Folder)

You can execute this through script or in the cmd line, requires admin rights!

script:

`system.util.execute(["cmd.exe","/C", "C:\\Folder\\UnlockAndDelete\\unlockAndDelete.bat","C:\\Program Files\\Inductive Automation\\Ignition\\webserver\\webapps\\main\\test1.jpg"])`

cmdline:

`"C:\Folder\UnlockAndDelete\unlockAndDelete.bat" "C:\Program Files\Inductive Automation\Ignition\webserver\webapps\main\test1.jpg"`

---

<div class="post-metadata">

**Author:** ![indenkleefj](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/indenkleefj/32/10961_2.png) [@indenkleefj](https://forum.inductiveautomation.com/u/indenkleefj)\
**Post date:** [October 22, 2024, 2:01pm UTC](https://forum.inductiveautomation.com/t/unblock-and-delete-files-that-have-been-locked-by-java/60194/2 "2024-10-22T14:01:43Z")

</div>

What would I need to do to unblock the file?  
`set fileName=%1 echo "%fileName%" for /f "tokens=3,6 skip=4 delims=: " %%I in ('%~dp0handle.exe %fileName% -p java.exe -accepteula') do %~dp0handle.exe -c %%J -y -p %%I`  
does not work.

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [October 22, 2024, 2:07pm UTC](https://forum.inductiveautomation.com/t/unblock-and-delete-files-that-have-been-locked-by-java/60194/3 "2024-10-22T14:07:34Z")

</div>

whats not working about it? maybe this only worked on certain windows version, i cant tell with so little info

---

<div class="post-metadata">

**Author:** ![indenkleefj](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/indenkleefj/32/10961_2.png) [@indenkleefj](https://forum.inductiveautomation.com/u/indenkleefj)\
**Post date:** [October 22, 2024, 2:34pm UTC](https://forum.inductiveautomation.com/t/unblock-and-delete-files-that-have-been-locked-by-java/60194/4 "2024-10-22T14:34:48Z")

</div>

The unlockAndDelete works on this window version. The script I shared does not unlock the file. When I execute it the file still says it's locked by java.exe. The CMD script I shared is in the same folder as the unlockAndDelete.bat.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/6/06b6aad8b0a4d5ac362309ad42e83a4c26f1109e.png)

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [October 22, 2024, 2:48pm UTC](https://forum.inductiveautomation.com/t/unblock-and-delete-files-that-have-been-locked-by-java/60194/5 "2024-10-22T14:48:17Z")

</div>

uh its all quite far away,  
but this is a bat code, not a cmd code

does the original bat work, executed as stated in my post?

---

<div class="post-metadata">

**Author:** ![indenkleefj](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/indenkleefj/32/10961_2.png) [@indenkleefj](https://forum.inductiveautomation.com/u/indenkleefj)\
**Post date:** [October 23, 2024, 6:02am UTC](https://forum.inductiveautomation.com/t/unblock-and-delete-files-that-have-been-locked-by-java/60194/6 "2024-10-23T06:02:10Z")

</div>

yes, the only thing I needed to change was: `"cmd.exe"` to `"C:\Windows\System32\cmd.exe"`

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [October 23, 2024, 6:31am UTC](https://forum.inductiveautomation.com/t/unblock-and-delete-files-that-have-been-locked-by-java/60194/7 "2024-10-23T06:31:58Z")

</div>

> [@victordcq](#):
>
> requires admin rights!

are you running this in admin rights?
