Is it possible to get the version number of a compiled program inside the program? I am using the Application Compiler.
Show older comments
For a project I am working on, I would like the program to output the current version being used in a char array. I have the following code:
if(isdeployed)
version = (Help here);
version_message = ['Now running program.exe version: ' version];
else
version = 'script';
version_message = ['Now running program.m version: ' version];
end
disp(version_message);
Is it possible to dynamically get the version number, or do I have to manually set it to ensure they are the same? I know it can be done with App Designer, but this executable does not use App Designer.
Accepted Answer
More Answers (2)
Image Analyst
on 8 Nov 2023
1 vote
You can get the version of MATLAB used, or you can get the date/time stamp of your executable, but you cannot get the version number/name you are calling your custom program. What I do is have a text file that keeps track of my version numbers and dates plus what changes were made in that version, and then I call the attached function to read my version number out of my text file (which I ship with my compiled program installer).
3 Comments
Eamon
on 8 Nov 2023
Image Analyst
on 8 Nov 2023
See attached utility functions, as well as a sample version of a version number file.
Eamon
on 8 Nov 2023
Eamon
on 8 Nov 2023
5 Comments
Eamon
on 5 May 2025
dpb
on 5 May 2025
OK, will move...one additional comment that with a compiled app I found the response time to the ."About" dialog was excessive when call the function directly to retrieve the version then. Consequently, I added it to the (already seemingly interminable) startup function code and stored it as a field in the app global data structure then for use later.
@Eamon, I have one Q? ...
commandStrings = string(System.Environment.GetCommandLineArgs);
name = char(commandStrings(1));
How did you find/know of the above in MATLAB? Even with it, I could find absolutely no reference in the documentation. A C program has them available as the arguments of the main() function; Fortran (officially with F2003, vendor extensions common prior) has the intrinsic subroutine get_command() so it is a routine thing to do...why MATLAB doesn't have a documented way is difficult to understand.
I don't see why the above should be considered "bad practice" other than it isn't documented...and to me that seems to be the really bad option. It didn't dawn on me until just yesterday about using this before; I had found another powershell workaround that read the uninstall registry key to find installed applications and then parse them which is a lot more fragile and risky than simply returning the command line that invokes the application.
Eamon
on 6 May 2025
Ah, so! I didn't think about the .NET connection, indeed! Thanks.
I guess while it isn't guaranteed by .NET or even by argv[0], that the loader for MATLAB Windows apps references the full file name is probably about as reliable as it gets without one of the real messy alternatives.
This app ends up installed in an IT-controlled environment and by default powershell scripts are disabled so it would require getting them to allow it for these machines to use that path. Single powershell commands can be executed with default permissions, so the version lookup can sneak under the radar.
And, as far as I can tell, there's no way to add additional installation tasks with the MATLAB-supplied installer to be able to do something more clever on the installation.
Categories
Find more on Introduction to Installation and Licensing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!