Having not found a batch script that did not try to either write a file to a system directory or relied on errorlevel
, I wrote the following script to be usable in other scripts or as a standalone tool.
You can alter the code to work in a script, or pass a username to the program to determine whether the user is admin. If no username is specified, the program checks the admin-hood of the current user.
@echo off
setlocal EnableDelayedExpansion
if "%~1" == "" (set user=%username%) ELSE (set user=%~1)
net user %user% | find "Local Group Memberships">temp.tmp
for /f %%a in ('findstr /i "Administrators" temp.tmp') do (
echo.
echo %user% is Admin...
echo.
set isadmin=y
del temp.tmp
pause
goto:eof
)
echo.
echo %user% is not Admin...
echo.
set isadmin=n
del temp.tmp
pause
goto:eof