Can I tell if Matlab is running with elevated privileges on Windows?

I would like to determine if the current Matlab session is running with elevated privileges (i.e. the user started it using "Run as administrator") under Windows. Ideally, the solution will work on XP and Windows 7, but I'm glad, if necessary, two solutions.

This answer assumes that I can get the information I need through the external .Net interface from Matlab (at least for Vista and later), but I wonder if there is a more β€œnative” Matlab solution.

+8
windows matlab uac
source share
1 answer

The Matlab.NET Bridge is for a different path - calling Matlab from .NET. Calling .NET classes from Matlab can be done quite simply using support for .NET external interfaces.

function out = isWindowsAdmin() %ISWINDOWSADMIN True if this user is in admin role. wi = System.Security.Principal.WindowsIdentity.GetCurrent(); wp = System.Security.Principal.WindowsPrincipal(wi); out = wp.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator); 

This should work with any version of Windows with .NET installed. A more native way would probably require writing MEX to invoke Win32 API functions, which would be more useful. Works on my XP machine.

+7
source share

All Articles