Main Content

comserver

Register, unregister, or query MATLAB COM server

Since R2020a

Description

comserver(action) registers or unregisters MATLAB® as a COM server in your user account without the need for administrative privileges. This syntax is equivalent to:

comserver('register','User','current')
comserver('unregister','User','current')

example

comserver(action,'User','all') registers or unregisters MATLAB for all users. To use this syntax, you must run MATLAB as an administrator.

example

comserver('query') displays installation paths of the registered MATLAB COM servers.

example

s = comserver('query') returns a structure with character vector fields:

  • User — Installation path of the MATLAB registered for the current user account

  • Administrator — Installation path of the MATLAB registered for all users

Examples

collapse all

Start MATLAB R2020a and type:

comserver('register')

You must have administrator privileges to register MATLAB as a COM server for all users.

Start MATLAB with the Run as administrator option. Based on your User Account Control (UAC) settings, you might need to right-click the Windows® Command Prompt or the MATLAB icon to select Run as administrator.

Once MATLAB is running, register MATLAB for all users:

comserver('register','User','all')

Suppose that your system has MATLAB R2019b and R2020a and your administrator registered R2019b as a COM server for all users.

You want to use MATLAB R2020a with a VBA application. Start MATLAB R2020a version and type:

comserver('register')

Verify the MATLAB version registered for your account.

comserver('query')
         User: 'C:\Program Files\MATLAB\R2020a\bin\win64\MATLAB.exe'
Administrator: 'C:\Program Files\MATLAB\R2019b\bin\win64\MATLAB.exe'

MATLAB displays the installation paths of the registered versions. The path for User is the MATLAB R2020a installation, so when you start your VBA application, it communicates with MATLAB R2020a.

If you start your VBA application using Run as administrator, then the application uses MATLAB R2019b.

Input Arguments

collapse all

Registration action, specified as one of these values.

'register'

Register this MATLAB as a COM server. This action replaces the previous registration, if any.

'unregister'

Unregister MATLAB as a COM server.

If you want to use the MATLAB registered by the administrator for all users, call:

comserver('unregister','User','current')

If you are an administrator and you want to change the COM server for all users, there is no need to unregister. Start the version of MATLAB you want to register and call:

comserver('register','User','all')

If you want to remove the MATLAB registered as a COM server for all users, call this statement. Any MATLAB registered for individual user accounts is unaffected.

comserver('unregister','User','all')

Data Types: char | string

Alternative Functionality

For users with administrative privileges, you can register and unregister MATLAB for all users from the Windows Command Prompt. For more information, see matlab (Windows). If you have multiple versions of MATLAB installed on your computer, the best practice is to run the matlab command from the matlabroot folder. To register MATLAB for all users, type:

matlab -batch "comserver('register','User','all')"

To unregister MATLAB for all users, type:

matlab -batch "comserver('unregister','User','all')"

Note

The comserver function is available for MATLAB R2020a and later. To register previous versions of MATLAB, type:

matlab -regserver
To unregister, type:
matlab -unregserver

Version History

Introduced in R2020a