In a recent project, I need get the installed Matlab’s executable path and their versions, and I know that users might not install Matlab in default “C:\Program files\MathWorks\…”.
The first solution that comes to my mind is to use the registry to find the desired results, as also shown in my previous post : How to get SolidWork exe path programmatically. It turns out that it is not as easy as it should be. Then I found another approach that really works well.
Every time when you install a Matlab version, Matlab installer will add the executable path to the system path, as shown below: (The snapshots come from my another freeware SysPathEditor)
So it is now easy to do the job:
- Get the system path
- Loop all items in the system path, and search with keywords with “Matlab” and “Bin”
- Return the ouptut.
Running the 7-line code snippet above, oh yeah~~~