Is it possible to get the version number of a compiled program inside the program? I am using the Application Compiler.
16 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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.
0 Commenti
Risposta accettata
dpb
il 1 Mag 2025
Modificato: dpb
il 5 Mag 2025
C:\>wmic /?
WMIC is deprecated.
[global switches] <command>
...
"Starting January 29, 2024, you'll find Windows Management Instrumentation Command line (WMIC) feature "disabled by default" on the insider build of Windows 11. ..." from <WMI command line (WMIC) utility deprecation: Next steps>.
Recommends using powershell instead but also notes that eventually the intent is to remove WMIC in some unspecified future release.
An Answer to another Q? posted an example of spawning powershell and parsing the return, I modified that a little to create a more generic utility function
function [status,version,cmdout]=getexeversion(app)
% return executable file version info
cmdout=[];
if ~isfile(app), status=-1; version=[]; return, end % no such file found
cmdstr=['powershell -command (Get-Command """',app,'""").Version'];
[status,cmdout]=system(cmdstr);
if status, version=[]; return, end % command failed
%elements=regexp(cmdout, '\d+', 'match'); % original stripped numbers returned powershell line,column if failed
%version=strjoin(regexp(cmdout, '\d+', 'match'),'.'); % long string returned as Major.Minor.Build.Revision
version=cell2struct(extract(cmdout,digitsPattern),extract(cmdout,lettersPattern)); % return as fields of struct instead
end
An example use would be something like...
>> fn=fullfile('C:\...\MATLAB\Work\','BuildBillingUtility/', ...
'for_redistribution_files_only/','AnnualBillingWorkbokUpdateTool.exe');
>> [s,v,c]=getexeversion(fn)
s =
0
v =
struct with fields:
Major: '4'
Minor: '0'
Build: '0'
Revision: '0'
c =
'
Major Minor Build Revision
----- ----- ----- --------
4 0 0 0
'
>>
where fn points to the built executable.
I put this into an 'About' menu item under an exisitng 'Environment' menu in the particular app to retrieve...all this then requires to manually enter into the app as a constant is the name of the executable so one doesn't have to update or include a version file that possibly can get out of synch. Of course, one would have to add in some way to keep the associated version notes if were to want that additional functionality.
As I noted in that other thread, it is certainly annoying one has to go to such machinations instead of being able to read the Sharing info that is in the app at the App level.
The test for file existence is a workaround that from MATLAB one cannot launch powershell directly; system or ! (bang) only know about CMD(*) so all one gets as a return code is the status of the outer shell, not the status returned by powershell itself. I wasn't able to find any way to manage that.
(*) This is also frustrating if one uses a command shell replacement such as the <Take Command> replacement from JP Software. It's such a pain that Mathworks ignores the user-defined default shell processor with the hardcoded "CMD.EXE" so that one cannot take advantage of the added features thus available. Of course, if one uses such, it isn't portable, but that shouldn't prevent from being able to use when do have...
0 Commenti
Più risposte (2)
Image Analyst
il 8 Nov 2023
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 Commenti
Image Analyst
il 8 Nov 2023
See attached utility functions, as well as a sample version of a version number file.
Eamon
il 8 Nov 2023
5 Commenti
dpb
il 6 Mag 2025
Modificato: dpb
il 6 Mag 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.
Vedere anche
Categorie
Scopri di più su MATLAB Compiler in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!