It is currently June 24th, 2019, 8:18 pm

Detecting the current user account type (admin vs. standard)

Tips and Tricks from the Rainmeter Community
User avatar
Posts: 631
Joined: June 25th, 2015, 7:02 pm
Location: The Sky, USA

Detecting the current user account type (admin vs. standard)

raiguard » June 22nd, 2018, 2:54 am

AFAIK there is no direct and straightforward way to tell whether the current user is an administrator or not. After a bit of fiddling around, I was able to find a command that did the trick when combined with a few other measures and values.

Code: Select all

IfTrueAction=[!CommandMeasure MeasureGetLocalGroup "Run"]

Parameter=net localgroup Administrators
FinishAction=[!EnableMeasure MeasureUserAdmin][!UpdateMeasure MeasureUserAdmin]

IfMatchAction=[!Log "User '[MeasureUserName]' is an administrator"]
IfNotMatchAction=[!Log "User '[MeasureUserName]' is not an administrator"]
This code retrieves the current username, then runs a command that lists all users in the "Administrators" user group. The third measure runs that command output through Regex to determine whether the given username is included in that group. The regex ensures a match only if the exact username is by itself (its own word). For example, if the username is 'Ben', who is a standard user, and there is another user 'Benjamin' who is an admin, the regex will not misidentify 'Ben' as an admin.
”We are pretty sure that r2922 resolves the regression in resolution caused by a reversion to a revision.” - jsmorley, 2017
User avatar
Rainmeter Sage
Posts: 3371
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Detecting the current user account type (admin vs. standard)

eclectic-tech » July 4th, 2018, 2:51 am

Thanks for sharing! :rosegift:

I looked at the "net" command's ability to list user groups, but never took the time to put it to use. :uhuh:

So thanks for saving me from figuring the extra steps to parse the string. :thumbup:

Adding this to my toolkit! :17nodding