+ Reply to Thread
Results 1 to 2 of 2

Thread: How to determine in batch-file, if user is administrator

  1. #1
    Junior Member
    Join Date
    Apr 2011
    Posts
    5

    How to determine in batch-file, if user is administrator

    Hi NG!

    Is there any possibility to determine in a batch-file, if the logged-on user is member of Administrators-Group?
    This should even work, if the user is member of a domain...

    Of course I can try, to create a file unter %SYSTEMROOT% or something else, and then check, if it was created... but perhaps there is a better practice?

    Any suggestion is greatly appreciated,

  2. #2
    Junior Member
    Join Date
    Apr 2011
    Posts
    3

    Re: How to determine in batch-file, if user is administrator

    in the batch, add the following lines to determine if the logged on user is a local administrator:

    set admin=N
    set domain=%USERDOMAIN%\
    If /i "%domain%" EQU "%computername%\" set domain=
    set user=%domain%%username%
    for /f "Tokens=*" %%a in ('net localgroup administrators^|find /i "%user%"') do set admin=Y


    Then just test the value of %admin%

    If "%admin% EQU "Y" goto isAdmin

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts