B4J Question [keyvaluestore] Installer for Standalone UI apps - Access denied when creating file in Program Files folder

rtek1000

Active Member
Licensed User
Longtime User
Hi,

I tried to create an app that creates an ".ini" file in the application folder (Final Install Folder: Program Files) but there was an error when the application tried to create a file.

I used this installer maker:

The ".ini" file is created with this library:

The standalone application is created with this function:

Error observed in debug mode when app tried to create ".ini" file:
C:\Program Files (x86)\MyApp\bin>java.exe @release_java_modules.txt -m b4j/b4j.example.main
(SQLException) java.sql.SQLException: opening db: 'C:/Program Files (x86)/MyApp/Init.ini': Access denied

This error did not occur when the app was run as an administrator.

But after the ".ini" file was created, it no longer needed to run the app as an administrator.

So I tried to make an installer that already left the ".ini" file created in the app folder, and it worked, it was not necessary to run the app as an admin.

Including the ".ini" file in the installer seems like an easy way to solve this problem, but it might be interesting to know how to get permission to write to this Program Files folder.

I found this but didn't test it:

Problem description:
I have written a Java application that includes a self updater. The self updater loads new program versions from a web server and replaces the application files. While this works perfectly if the application is installed e.g. in the users home directory, it fails on windows machines if it's installed in the C:\Program Files folder. This is because the JVM is executed under the user’s account which has no write access to the program directory. If a native program, e.g. an installer, tries to write to the program folder, usually a popup appears asking the user to permit the write operation. This doesn’t happen for java applications. Why?

Possible solution:
If you are using inno setup compiler to generate your launcher, then you can change your app directory permission.
For example, if you need full control and want to update files under AppName/data folder
[Dirs]
Name: "{app}";
Name: "{app}\data"; Permissions: everyone-full

[Files]
Source: data\*; DestDir: {app}\data\; Flags: ignoreversion recursesubdirs createallsubdirs; Permissions: everyone-full

Source: https://stackoverflow.com/questions/21052384/write-to-c-program-files-from-java-program
 

rtek1000

Active Member
Licensed User
Longtime User
You should use XUI.DefaultFolder
Thank you

b4x_df_path.png


b4x_dd_path.png
 
Upvote 0
Top