Windows IT Pro is the leading independent community for IT professionals deploying Microsoft Windows server and client applications and technologies.
  
  
  Advanced Search 


August 1999

Group-Aware Logon Scripts


RSS
Subscribe to Windows IT Pro | See More Resource Kit Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

Ifmember and KiXtart add flexibility

Write a few logon batch scripts, and you'll soon be disappointed with their shortcomings. The basic problem with batch scripts is that they're only batch files and are no more capable than batch files.

For example, suppose you're writing a batch file and you want one kind of action to occur when an administrator runs the file and another kind of action to occur when a user runs the file. More specifically, say you have a share with some administrative tools in it called \sxl0\atools; you want to map that share to drive W when an administrator logs on but not map the drive when a nonadministrative user logs on. How do you make this distinction? How do you tell a batch file that someone's in a particular group? The command interpreter, cmd.exe, doesn't provide one simple tool, but the Microsoft Windows NT 4.0 Resource Kit includes a couple of useful tools. This month, I describe these resource kit tools that let you write more powerful batch files.

If you are an old-time NT, Windows, or DOS batch expert, you'll appreciate the resource kit's Ifmember. Many resource kit utilities run on a server, so you don't need to distribute them to workstations. But ifmember.exe is a client-side tool and needs to be present on or available to each user's workstation to work. You can put ifmember.exe on every user's hard disk, but that's too much work. An easier way is to put ifmember.exe into the same directory as the logon batch files. (The Netlogon directory is the default directory when the logon batch file is running. Ergo, putting a program into Netlogon installs the program instantly, hands-off.)

Ifmember is a simple program; it looks like

IFMEMBER groupl group2 group3...

where the groups are the names of user groups. If the group's name includes a space between letters, such as Domain Admins, enclose the name in quotation marks. If the person running Ifmember is a member of one of the groups named, Ifmember ends with return code 1. You can then use Errorlevel to test for this return code's occurrence, as in the following example:

@echo off
ifmember "domain admins"
if not errorlevel 1 goto user
echo you're an admin!
goto quit
:user
echo just a regular user

This batch file checks your groups to see whether you're a member of the Domain Admins group. (Note that Ifmember isn't case-sensitive.) The next line, if not errorlevel 1 goto user, checks whether your return code is equal to 1. If the code isn't 1, the batch file skips ahead to the user: line. Then, the file displays the message just a regular user and ends. However, if the return code is equal to 1, the batch file runs the next line, displays you're an admin!, and jumps to the end of the batch file. You can implement the previous drive map example as follows:

@echo off
ifmember administrators "domain admins"
if not errorlevel 1 goto quit
net use w: \\sxOl\atools
:quit

However, Ifmember works on only NT workstations. For Windows 9x machines, KiXtart is your only option. Although the official name is KiXtart 95, you can use KiXtart to build very flexible batch files on NT and Win9x workstations. KiXtart is a complete programming environment, with a comprehensive programming language using If...Then...Else constructs and Goto and Select statements, and includes nearly all the program control you find in Basic programming. KiXtart also has a rich set of built-in functions, including a function named Ingroup, which lets you write program lines such as

IF INGROUP("Domain Admins") RUN "net use w: \\sxOl\atools"

Logon batch scripts might still cause you some frustration, but Ifmember and KiXtart will help you write significantly more flexible logon batch scripts.

End of Article



Reader Comments
I am the IT manager of two east coast facilities for my employer. Recently we had a meeting via conference call to all sites that participate in our WAN. A priority is to simplify our LANS so that they are consistant between sites. In the past each site had several log on scripts to accomodate different user groups.

I had remembered reading this article in my printed version of the magazine. Luckily I am a member of your online service as well and did a quick search on ifmember.exe. Using the information outlined in this article we will be able to accomodate all users using a single log on script. Duplicating this approach at each site will enable us to take a giant step in the simplification and consistancy of each domain participating in the WAN.

Thank You Very Much!


Scott M. Hermans December 08, 1999


This is another short coming of NT. Novell has polished this down to a science. The extensive lists of Novell Variables that can be used dwarf what NT can do. Hopefully there are easier to use tools out there than what are mentioned in this article.

Ron Bronson January 23, 2001


Recently I found that ifmember.exe fails when using windows 2000 group names and it would only work if I used pre-windows 2000 name of the group, any ideas?

Thanks,
Jason

JHawi December 30, 2004 (Article Rating: )


You must be a registered user or online subscriber to comment on this article. Please log on before posting a comment. Are you a new visitor? Register now




Top Viewed ArticlesView all articles
Confirmed: Battery Life Issues Not Windows 7's Fault

Microsoft on Monday issued a lengthy statement about the recent Windows 7 battery controversy, echoing my assessment from earlier in the day, but backing it up with hard, cold evidence. ...

Battery Life Issues Almost Certainly Not Windows 7's Fault

While Microsoft is still investigating a notebook battery life issue that was supposedly caused by Windows 7, some interesting trends have emerged. ...

Microsoft Warns of Windows Version Expirations

Microsoft warned that this year will see three out-of-date Windows versions slip into retirement. ...


Task Automation Whitepapers Three Ways to Prevent Insider Risk within Your SCCM-Managed Environment

From Development to Production: Streamlining SharePoint Deployment with DocAve Deployment Manager

Related Events Deep Dive into Windows Server 2008 R2 presented by John Savill

Check out our list of Free Email Newsletters!

Task Automation eBooks Spam Fighting and Email Security for the 21st Century

A Guide to Windows Certification and Public Keys

Keeping Your Business Safe from Attack: Patch Management

Related Task Automation Resources Introducing Left-Brain.com, the online IT bookstore
Looking for books, CDs, toolkits, eBooks? Prime your mind at Left-Brain.com

Discover Windows IT Pro eLearning Series!
Clear & detailed technical information and helpful how-to's, all in our trademark no-nonsense format


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro DevProConnections IT Job Hound
Left-Brain.com Technology Resource Directory asp.netPRO ITTV Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2010 Penton Media, Inc. Terms of Use | Privacy Statement