How do I address issues with write permissions for applications created using MATLAB Compiler?

13 views (last 30 days)
I am developing an application using MATLAB Compiler which is installed on a user's computer. A frequent issue that I encounter is that users generally don't have write permission to the installation directory "C:\Program Files" as part of Windows User Account Control (UAC), nor do they have admin permissions. Even if an admin installs the application, the user will encounter problems because the application needs to write files to the user's system. 
What is the recommended way to work around this?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 25 Aug 2022
Try one of the following workarounds:
  1. Install the app outside of "C:\Program Files". During installation, you may change the installation folder, however, keep in mind that you will have to remember the new installation folder when updating the app in the future.
  2. Use "compiler.build" and "compiler.package" to create an installer with a non-Program Files install location. See the link below for further information:\n
    Unlike the Application Compiler, which limits the choices to "%PROGRAMFILES%" and "%APPDATA%", "compiler.package" provides the ability to specify any folder (e.g., "C:\CustomPrograms\<applicationName>") as the installation location through the "DefaultInstallationDir" option. With this workaround, the user does not need to remember the location.
  3. Update the program to read and write to files outside of the "Program Files" folder.
If none of the above workarounds resolves this issue, make a simplified app by following the steps below:
1) Create a simple function that takes two arguments. The first is the name of the file, and the second is a string to append to that file. See the code below:
function testWrite(filename, data)
fid = fopen(filename, "a");
fprintf(fid, data);
fclose(fid);
end
2) Create an empty "data.txt" file in the same folder. Ensure that the "Current Folder" within MATLAB contains the function file and "data.txt".
3) Compile the function using the Application Compiler. To do this, type the following in the MATLAB Command Window:
>> applicationCompiler
Make sure to include the "data.txt" file in the "Files installed for your end user" section so it gets installed alongside the application. The next steps assume you named the project "testWrite".
Make sure to uncheck "Do not display the Windows Command Shell (console) for execution" before packaging the app.
4) Run the generated installer and install the program to "C:\Program Files\testWrite\".
5) Open Windows' Command Window and "cd" to "C:\Program Files\testWrite\application".
6) Confirm that, after this initial installation, you get errors running the program and trying to append data to the "data.txt" file, or by trying to write data to a new file. See an example of the errors below:
C:\Program Files\testWrite\application>.\testWrite.exe data.txt bar
Error using fprintf
Invalid file identifier. Use fopen to generate a valid file identifier.
Error in testWrite (line 4)
MATLAB:FileIO:InvalidFid
---
C:\Program Files\testWrite\application>.\testWrite.exe foo3.txt bar
Error using fprintf
Invalid file identifier. Use fopen to generate a valid file identifier.
Error in testWrite (line 4)
MATLAB:FileIO:InvalidFid
7) Ensure that:
7a) Granting regular users the privilege to modify "data.txt" allows them to use the app to edit the file.
7b) Granting regular users the privilege to modify within "C:\Program Files\testWrite\application" allows them to use the app to create new files.
8) At this point, we are unable to reproduce this issue. If running the installer for a second time does reproduce this issue, the cause of this issue is unique to your environment.
However, if you are not able to reproduce it after following the previous steps, try tweaking the previous steps so they mimic how your app functions. Note that it is important that the app remains as lightweight as possible so we have an easier time investigating this issue. If you are able to reproduce this issue after making some tweaks to the reproduction process, contact technical support and send us the exact steps you took as well as the reproduction app's source code if possible.

More Answers (0)

Categories

Find more on Introduction to Installation and Licensing in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!