<http://www.netikka.net/tsneti/info/tscmd189.php>
Copyright © 2013- by Prof. Timo Salmi  
Last modified Sat 14-May-2016 17:49:08
Welcoming the user from 54.221.93.187
On Mon 18-Dec-2017 11:05:00 server time

 
Assorted NT/2000/XP/.. CMD.EXE Script Tricks
From the html version of the tscmd.zip 1cmdfaq.txt file
To the Description and the Index
 

This page is edited from the 1cmdfaq.txt faq-file contained in my tscmd.zip command line interface (CLI) collection. That zipped file has much additional material, including a number of detached .cmd script files. It is recommended that you also get the zipped version as a companion.

Please see "The Description and the Index page" for the conditions of usage and other such information.



189} How do I test if the current user has administrator rights?

Entirely due to others:
  @echo off & setlocal enableextensions
  net localgroup administrators|findstr /b /e "%USERNAME%" > nul
  if %errorlevel% EQU 0 (
    echo The current user %USERNAME% has administrator rights
    ) else (
    echo The current user %USERNAME% does not have administrator rights)
  endlocal & goto :EOF

My own, similar XP-only solution
  @echo off & setlocal enableextensions
  net session 2>&1 > nul
  if %errorlevel% EQU 0 (
    echo The current user %USERNAME% has administrator rights
    ) else (
    echo The current user %USERNAME% does not have administrator rights)
  endlocal & goto :EOF

Another, even simpler one. Also XP-only
  @echo off & setlocal enableextensions
  fsutil > nul
  if %errorlevel% EQU 0 (
    echo The current user %USERNAME% has administrator rights
    ) else (
    echo The current user %USERNAME% does not have administrator rights)
  endlocal & goto :EOF

For Windows 7 (and probably beyond)
@echo off & setlocal enableextensions
net user %USERNAME%|findstr /i /c:"Local Group Memberships"|findstr /i /c:"*Administrators">nul
if %errorlevel% EQU 0 (
  echo User %USERNAME% has administrator rights
  ) else (
  echo User %USERNAME% does not have administrator rights)
endlocal & goto :EOF

References/Comments:
  Google Groups 14 Feb 2013 14:19:20 +1100
  Google Groups 14 Feb 2013 12:19:22 +0800
  Google Groups 14 Feb 2013 01:30:04 -0800