jpackage - "IOException: Access denied" when accessing app folder when installer requires admin privilege

46 Views Asked by At

I'm making a simple Java desktop application using jpackage for native exe installer.
But when I make an installer and test on two different PCs, the installer requires me an admin privilege in one of my computer(A).
While in another computer(B), it does not require any privilege.
Installation window in PC (A, admin privilege required)
Installation window in PC (B, admin privilege not required)

Permitting installation is not a big deal, as both PC is logged on as an administrator. But in case (A), the application is unable to access files in its installation folder(C:\Program Files\PMailSender\app\*). Which means this code :

//ConfigFilePathGetter.getProjectPath() returns "C:\Program Files\PMailSender\app\"
File f = new File(ConfigFilePathGetter.getProjectPath() + "config.txt");
if(!f.exists()) f.createNewFile();

Throws :

java.io.IOException: Access is denied.
    at java.base/java.io.WinNTFileSystem.createFileExclusively(Native Method)
    at java.base/java.io.File.createNewFile(File.java: 1043)

Whereas in case (B), the app can freely access files in the installation folder without any Exception.

I wonder what causes the same installer file requires admin privilege in one PC, but not the other. I believe it's the main cause of the main problem(access denied)
Both are logged in as an administrator account, and only difference I found out(for now) is that (A) is Microsoft account, whereas (B) is local account.

If the problem is in my Windows account, how to solve it? If not, what would be the problem?

I used Adoptium jdk 17.0.10 and org.panteleyev:jpackage-maven-plugin for jpackage support in maven.

  • Note : when tested in MacOS, if the installer type is set to .pkg, the application cannot access the app installation directory(in this case, /Applications/PMailSender.app/Contents/app/) too, whereas when I set the installer type to .dmg, there's no problem.
java.io.IOException: Permission denied
    at java.base/java.io.UnixFileSystem.createFileExclusively(Native Method)
    at java.base/java.io.File.createNewFile(File.java:1043)
0

There are 0 best solutions below