Unblock and Delete files that have been locked by Java

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.

I made it a bit easier to use by writing a simple bat file.
UnlockAndDelete.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"

3 Likes

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.

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

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.

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?

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

are you running this in admin rights?

1 Like