Discussion Locked

run different login script when logon

0 helpful
13 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hi, everyone:

How can I write a login script that can differentciate users and execute different login script commands. For example: if a student logon, it runs Student.bat, if a teacher logon, it runs Teacher.bat. If this is possible, what is the syntax for that command ?

13 replies

by joseph moore

Well, normally this is done by using different logon scripts. You assign student.bat to the student user accounts, and teacher.bat to the teacher accounts. You don't have to use the same logon script for all accounts.
But, if you still want to knowa way, then there is one. There is a variable called %USERNAME% that you can use. This variable will = the user name that the user typed into the User Name box in the logon window.
For example, say you have user BOB who is a teacher, user TOM who is a student, and user JIM who is another teacher. All 3 users use LOGON.BAT as their logon script. The beginning of LOGON.BAT looks like this:

@echo off
IF %USERNAME% == BOB CALL TEACHER.BAT
IF %USERNAME% == bob CALL TEACHER.BAT
REM continue with students logon script drive mappings and such....

So, those IF %USERNAME% lines say if BOB logs in, then call ANOTHER batch file called TEACHER.BAT and do whatever TEACHER.BAT says to do. Now, the %USERNAME% variable IS case-sensitive, so "BOB" and "bob" both need to be in. From my experience, those are the normal user names that people use, either all capitals or all lower case. You normally don't see people logging in with user name "Bob".
Now, the TEACHER.BAT file has all of the logon script parameters for teachers. The very IMPORTANT thing to remember about TEACHER.BAT is that the very last line in that BAT file must be this:
EXIT

If you do not have the EXIT at the end of TEACHER.BAT, then the logon script process will continue AFTER TEACHER.BAT has finished, and it will go back to LOGON.BAT and continue doing stuff! If you EXIT at the end of TEACHER.BAT, that will end the whole session at that point; it won't loop back to LOGON.BAT and continue.

Last, the rest of LOGON.BAT has the logon script info for the students.

by joseph moore

So, try this, if you can't use different logon scripts in the user accounts.
Keep LOGON.BAT and TEACHER.BAT both in the NETLOGON share on your NT PDC and BDCs.

One last thing: there is another way to do this, using the IFMEMBER.EXE tool from the Windows Resoruce Kit. It is a little less clunky, but you need the Kit first.

hope this helps

by vh_s

Agree as answer 1. Use %username% to differentiate between users.

Or, otherwise set that directly into your user profile. Select the group the users belong to (multiple users will be selected), click properties, click user profile. And at the logon script dialog box, just enter the logon script you would like to run whenever one of the users of this group log-in into the network.

At the bottom of each logon script attach something like COMMON.BAT, allowing each login script to execute script COMMON.BAT, to set common setting for all login script.

vh_s

by vh_s

Uh, I see answer #4.

Yes, it is true that for Win9x machines the %username% won't work, since Windows doesn't have any username environment variables.

So, in a mixed OS, I did the following. In user profile, enter a login entry script and add a %username% as parameter.
Example:

Logon Script: WELCOME.BAT %username%

So, NT server would replace that %username% with the correct username. Inside the script, do an if filter-ing.

if "%1"=="" goto EmptyParm
if %1==USER1 goto User1Exec
if %1==USER2 goto User2Exec
goto NormalExec

:User1Exec
rem execute login script for user1
goto End

:User2Exec

etc.....

vh_s

by oskiller

The %USERNAME% thing will work, but as stated in answer 2, your best bet is to associate the script directly with the ID. If a logon script starts getting long and complicated, errors can happen, as well as increasing the login time due to the script having to check for things that are not needed.

by spank

I agree with the previous answers. However, unless I'm mistaken, the %username% variable won't work with Win9x machines.

by maddiuex

The answers above are great, and I however use Kix to run the scripts. It is a very resourcful tool and It may be another tool for you to consider. http://kixtart. org/
( Please remove any spaces )

Hope this helps

This discussion is closed to new replies.