
Today let’s start at the foundation of login scripts. Login scripts represent one of the easiest ways you can reach out and touch your users when they get on your network.
The login scripts that I have dealt with started with KiXtart (thankfully I managed to skip most of Netware). Using KiXtart we did simple automation of drive mappings and similar items. Over time I began to use KiXtart for more elaborate automation. Then in 2000 I began working with the then relatively new Windows Script Host. Since then WSH has been the basis of my login scripts for Windows clients. Using WSH you can access a wealth of external sources to draw a lot of power into your scripts.
Today my basic login script utilizes:
- Windows Script Host: WSH is the core provider for the scripting environment
- VBScript: I have written most login scripts in VBScript, although WSH can run other languages such as javascript.
- ADSI: The Active Directory Services Interface (ADSI) provides access to user and group information that drives many of the decisions within the script logic.
- WMI: The Windows Management Instrumentation (WMI) is the Microsoft flavor of WBEM which provides access to system level information about Windows hosts.
“So…” you may be saying to yourself “that’s all well and good, but how do I put this to use?” Well, for this installment, I’m going to lay out the basic setup for the scripts I use. This won’t do much, but it does set the stage for all other pieces. In later entries, we’ll look at useful things to do with it.
‘===========================
‘ Domain Login.vbs
‘ Simple Windows Script Host login script
‘===========================
On Error Resume Next
‘Get a reference to the WSH Network object
set WSHNetwork = CreateObject(“WScript.Network”)
‘Get a reference to the WSH Shell object
set WSHShell = CreateObject(“WScript.Shell”)
‘Get a reference to the FileSystemObject
Set fso = CreateObject(“Scripting.FileSystemObject”)
‘Get the user’s network ID
Username = WSHNetwork.UserName
‘Get the computer’s name
Computername = WSHNetwork.Computername
‘Bind to the user’s account on the network
Set UserObj = GetObject(“WinNT://DOMAINNAME/” & username & “,user”)
‘Build a list of all groups the user is a member of
for each grp in UserObj.Groups
GroupList = GroupList & grp.name & vbCrLf
next
‘Get local profile paths
Set WSHEnvProcess = WshShell.Environment(“Process”)
ProfileUserPath = WSHEnvProcess(“USERPROFILE”)
ProfileAllUsersPath = WSHEnvProcess(“ALLUSERSPROFILE”)
‘Login Message
‘=============
sLoginMessage = “Welcome to the network.” & vbCRLF
sLoginMessage = sLoginMessage & “—————————————” & vbCRLF
sLoginMessage = sLoginMessage & “Click OK to continue to login to your computer.” & vbCRLF
wscript.echo sLoginMessage
‘===============
‘ Script content
‘ goes here.
‘===============
This shell creates references to items we’ll need later, fetches the user name and computer name, and then connects to AD (or NT4 domain) to retrieve the user’s group membership. The paths for some local profile directories is discovered and a welcome message is displayed to the user.
That’s it so far. Nothing terribly interesting, but we’ll have much more fun with this as we go along.
FieldNotes