PC Review


Reply
Thread Tools Rate Thread

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

 
 
Heiko Pliefke
Guest
Posts: n/a
 
      4th Aug 2005
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,

Best regard,
/Heiko Pliefke
 
Reply With Quote
 
 
 
 
Jerold Schulman
Guest
Posts: n/a
 
      4th Aug 2005
On Thu, 04 Aug 2005 16:18:39 +0200, Heiko Pliefke <(E-Mail Removed)> wrote:

>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,
>
>Best regard,
>/Heiko Pliefke


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 With Quote
 
Marty List
Guest
Posts: n/a
 
      4th Aug 2005

Try IFMEMBER.EXE from the Windows Server 2003 Resource Kit Tools:
http://www.microsoft.com/downloads/d...e-b18c4790cffd



"Heiko Pliefke" <(E-Mail Removed)> wrote in message
news:1123165119.614281@nbgm66x...
> 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,
>
> Best regard,
> /Heiko Pliefke



 
Reply With Quote
 
Bill Stewart
Guest
Posts: n/a
 
      4th Aug 2005
Jerold Schulman wrote:

> 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


It would seem that this method would fail if the user is a member of a
group that's a member of Administrators.

Ifmember.exe doesn't have this problem, but it's not language-independent.

To address these issues, I wrote isadmin.exe:

http://www.cybermesa.com/~bstewart/wast.html

Internally, isadmin.exe enumerates the SIDs for the current user and
returns an exit code of 1 if the current user is a member of
Administrators (e.g., SID S-1-5-32-544).

--
Bill Stewart
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: determine version of .exe thru batch file Jon Windows Vista General Discussion 0 2nd Jun 2009 06:03 PM
How to Determine if Administrator is Logged On user? Vince Windows XP Help 2 6th Jul 2005 07:55 AM
Batch file to determine if your HD is NTFS if not Format:FTFS Mr Prince Microsoft Windows 2000 CMD Promt 2 6th Apr 2004 11:21 PM
Batch file to determine if your HD is NTFS if not Format:FTFS Microsoft Windows 2000 CMD Promt 2 6th Apr 2004 08:23 PM
Determine service pack level from a batch file. David Microsoft Windows 2000 4 6th Jan 2004 12:18 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:44 PM.