JSI Tip 4905. An alternative to the Ifmember command


I find that the Windows 2000 Resource Kit is an indispensable tool for managing a Windows 2000 environment.

The Windows 2000 Server Resource Kit Supplement One is a CD-ROM that contains all the server and Professional tools, as well as the online documentation for both Server and Professional.

Microsoft has some Windows 2000 Resource Kit utilities in the public domain, but even if all the tools were available, the help files, registry, policy, and event references would make this CD-ROM an valuable acquisition.

In tip 4630, I scripted an alternative to the Sleep command.

"IfMember is a command-line tool that checks whether the current user is a member of a specified group. It is typically used in Windows logon scripts and other batch files.

IfMember uses its own process token to discover group membership, rather than querying the relevant domain controller each time it runs. While this has a significant performance benefit, it does mean that IfMember will only be aware of groups on the local computer, on the computer's domain, and on trusted domains."

I have scripted two alternatives to the Ifmember tool, IsLocal.bat and IsDomain.bat. The syntax is:

IsDomain UserName DomainGroup

IsLocal UserName LocalGroup

Both scripts return a $Member environment variable, which is set to Y or N.

Sample Usage:

call IsDomain "%userName%" "Domain Admins"
if "%$Member%" EQU "Y" goto UserIsDomainAdmin

call IsLocal "%username%" "Administrators"
if "%$Member%" EQU "Y" goto UserIsLocalAdministrator

call IsLocal Jerry Administrators
if "%$Member%" EQU "Y" goto UserIsLocalAdministrator

IsDomain.bat contains:

@echo off
set $Member=N
if \{%2\}

\{\} goto :EOF net user %1 /domain | find /i %2 >nul if not errorlevel 1 set $Member=Y

IsLocal.bat contains:
@echo off
set $Member=N
if \{%2\}\{\} goto :EOF
net user %1 | find /i %2 >nul
if not errorlevel 1 set $Member=Y


Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish