Wrong warning about protected install location

Dear all,

is there a way to get rid of the following warning, without changing the install directory?
"[WARNING] Your ImageJ installation cannot be updated because it is in a protected location (e.g., “C:\Program Files”).
Please move your installation to a directory with write permission"

Yes, our installation is in a subdir of “C:\Program Files” and it should be located there (because of our specification). We made the ImageJ directory writeable by users, so yes, it is writeable. E.g. with user permissions, I can update it, despite the warning. It seems, that the directory check is hardcoded somewhere without actual confirming if it is write protected or not.

Is it possible to include in one of the newer version a small check, if the directory is actual write protected before showing the warning? It is really annoying to have the warning window pop up at every start and this also irritates most of our users.

Thanks in advance and also thanks for the great software. :slight_smile:


Indeed, the check is hardcoded.

The commit which introduced this behavior is here. However, IIRC, Johannes hard coded it because there were cases where Windows would purport to allow writes in small tests, but in practice it did not work. That said, it is very likely possible to write some more robust and generalized test code. If you have the time and energy to submit a patch as a pull request, that would be most excellent. One option is to generalize the check; another would be to simply add a system property or setting which toggles the check, so that you can disable it for your users.


Continuing the discussion from Wrong warning about protected install location:

Hey @ctrueden,

thanks for your answer and sorry for my (very) long delay. I patched it locally for me, but it would be nice to have it patched at the source.

It’s a while since I did some coding and I don’t have a github account (so no official pull request), but I hope I did it right, the git patch I’m pasting here will work and that the code is OK for you.


diff --git a/src/main/java/net/imagej/updater/util/UpdaterUtil.java b/src/main/java/net/imagej/updater/util/UpdaterUtil.java
index 9ac69b3..8fece81 100644
--- a/src/main/java/net/imagej/updater/util/UpdaterUtil.java
+++ b/src/main/java/net/imagej/updater/util/UpdaterUtil.java
@@ -530,7 +530,10 @@ public class UpdaterUtil {
 					}) {
 						final String path = System.getenv(key);
-						if (path != null) protectedFiles.add(new File(path).getCanonicalFile());
+						if (path != null) {
+							File f = new File(path).getCanonicalFile();
+							if (!f.canWrite()) protectedFiles.add(f);
+						}
 				for (File dir = ijRoot.getCanonicalFile(); dir != null; dir = dir.getParentFile()) {

Thanks and all the best,

@mh_c Thanks! I pushed it:


Dear Curtis,

that’s great. Many thanks :slight_smile: