HI guys and gals,

I'm trying to get a login script I have put together working... It's an
amalgamation of scripts I have found online. My goals are:

1: Automate Network Printer deployment based upon user group
membership. Printer lists will be stored in text files, one for each
group.

2: Automate Network Drive deployment, again based on group membership.
Network shares and drive letters are specified in a text file.

3: Display a login prompt.

I've almost got this working but there are a couple of problems:

1: Printer assignment works, but the text file must be in alphabetical
order... maybe there is a better way to do this? Possibly using a
similar loop to the Netwrk Share

2: The network share is not working at all. I had it working simillaly
to the printer Sub but noticed the alphabetical problems .

Any help with this would be greatly apreciated.

I have pasted the code below to the script... it is long. Below this
are examples of the text files.

========================================================================

'Test VBS Login Script

'*******Determin Active Directory Account Information by binding to the
user object in AD***********

' Constants for the NameTranslate object.
Const ADS_NAME_INITTYPE_DOMAIN = 1
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1179 = 1

Dim Filesystem
Dim InPutFile
Dim arrname

Dim clPrinters
Dim strPrinterName
Dim printer_file

Dim network_share_file
Dim strNetworkShare
Dim strDriveLetter
Dim clshares

Set objNetwork = CreateObject("Wscript.Network")

'Retrieve Computer Name
strComputerName = objNetwork.ComputerName

' Retrieve user NT logon name.
strNTName = objNetwork.UserName

' Determine DNS domain name from RootDSE object.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")

' Use the NameTranslate object to find the NetBIOS domain name from the
' DNS domain name.
Set objTrans = CreateObject("NameTranslate")
objTrans.Init ADS_NAME_TYPE_NT4, strDNSDomain
objTrans.Set ADS_NAME_TYPE_1179, strDNSDomain
strNetBIOSDomain = objTrans.Get(ADS_NAME_TYPE_NT4)
' Remove trailing backslash.
strNetBIOSDomain = Left(strNetBIOSDomain, Len(strNetBIOSDomain) - 1)

' Use the NameTranslate object to convert the NT user name to the
' Distinguished Name required for the LDAP provider.
objTrans.Init ADS_NAME_INITTYPE_DOMAIN, strNetBIOSDomain
objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & "\" & strNTName
strUserDN = objTrans.Get(ADS_NAME_TYPE_1179)

' Bind to the user object in Active Directory with the LDAP provider.
Set objUser = GetObject("LDAP://" & strUserDN)

' Display various names.

'************** Find current time and date and display login
prompt****************************

On Error Resume Next

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer &
"\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_LocalTime")

For Each objItem in colItems
intMonth = objItem.Month
intDay = objItem.Day
intYear = objItem.Year

dtmDate = intMonth & "/" & intDay & "/" & intYear

intHour = objItem.Hour

If intHour < 12 Then

text1 = "Morning"

ElseIf intHour => 12 And intHour < 18 Then

text1 = "Afternoon"

ElseIf intHour > 18 Then

text1 = "Evening"

End If

intMinutes = objItem.Minute
If intMinutes < 10 Then
intMinutes = "0" & intMinutes
End If

intSeconds = objItem.Second
If intSeconds < 10 Then
intSeconds = "0" & intSeconds
End If

dtmTime = intHour & ":" & intMinutes & ":" & intSeconds

MsgBox ("Good " & text1 & " " & objUser.givenName & " " &
objUser.sn & " and welcome to the Spicers European Network." _
& vbCRLF _
& vbCRLF & "You are logging into computer " & strNetBIOSDomain &
"\" & strComputerName & "." & vbCRLF _
& vbCRLF & "The current date and time is: " & dtmDate & " " &
dtmTime _
& vbCRLF _
& vbCRLF & "Please note that all system usage is monitored and that
by clicking OK below, you"_
& vbCRLF & "confirm that you understand & accept this as part of
the SPICERS IT User Policy."_
& vbCRLF & "Please note that this policy is subject to periodic
update and you are advised"_
& vbCRLF & "to refresh yourselves with the contents of the policy
on a regular basis."_
& vbCRLF _
& vbCRLF & "A copy of the IT User Policy can be found in:"_
& vbCRLF & "Public folders/Employee policies & Procedures/IT User
Policy - Spicers Limited")
Next

'*******Establish group membership and process script based upon AD
group Membership***********

If IsMember("Domain Admins") Then

WScript.Echo "Member of Domain Admins = Yes"
printer_file = "domain_admins_printers.txt"

Install_NetPrinters
Install_Printer

network_share_file = "domain_admins_shares.txt"
Install_NetShares
Install_Share
End If

If IsMember("Retriever") Then
WScript.Echo "Member of Retriever = Yes"
Else
WScript.Echo "Member of Retriever = No"
End If

If IsMember("Euro") Then
WScript.Echo "Member of Euro = Yes"
Else
WScript.Echo "Member of Euro = No"
End If

Function IsMember(strGroup)
' Function to test one user for group membership.
' objUser is the user object with global scope.
' strGroup is the NT Name of the group to test.
' objGroupList is a dictionary object with global scope.
' Returns True if the user is a member of the group.

Dim objGroup
If IsEmpty(objGroupList) Then
Set objGroupList = CreateObject("Scripting.Dictionary")
objGroupList.CompareMode = vbTextCompare
For Each objGroup In objUser.Groups
objGroupList(objGroup.sAMAccountName) = True
Next
End If
IsMember = objGroupList.Exists(strGroup)
End Function

'********************************* Printers Functions
********************

Sub Install_NetPrinters

Set clPrinters = objNetwork.EnumPrinterConnections
Set FileSystem = WScript.CreateObject("Scripting.FileSystemObject")
ForReading = 1

Set InPutFile = FileSystem.OpenTextFile(printer_file,ForReading, False)

'Overwrite Flag
intInstallPrinterFlag = 0

End Sub

Sub Install_Printer

While not InPutFile.atEndOfStream

If clPrinters.Count <= 0 Then

uname = InPutFile.ReadLine()
arrname = Split (uname,"")
strPrinterName = arrname(0)

Wscript.Echo "Printer: " &
strPrinterName & " Does Not Exist"
objNetwork.AddWindowsPrinterConnection
strPrinterName
'To Set this printer as a default
printer enable the next line
'objNetwork.SetDefaultPrinter
strPrinterName
WScript.Echo "Installing " &
strPrinterName
'Now, if there is a printer installed
and the install printer flag
is set, then remove the existing printer and re-install it.

ElseIf clPrinters.Count > 0 Then

'To display current printers
For i = 0 to clPrinters.Count -1 Step 2

Wscript.Echo "Query returned: "
& clPrinters.Item (i + 1)

uname = InPutFile.ReadLine()
arrname = Split (uname,"")
strPrinterName = arrname(0)

If lcase(clPrinters.Item (i +
1)) = lcase(strPrinterName) then

Wscript.Echo "Printer
connection to " & strPrinterName & "
Exists, checking Re-Install Flag"

If
intInstallPrinterFlag = 1 Then
WScript.Echo
"Printer connection to " & strPrinterName &
"exists, re-install flag SET. Removing and re-installing."

objNetwork.RemovePrinterConnection strPrinterName

objNetwork.AddWindowsPrinterConnection strPrinterName
WScript.Echo
"Installing " & strPrinterName
Else
WScript.Echo
"Printer connection to " & strPrinterName &
"exists, but re-install flag NOT SET, discarding."

End If

Else

Wscript.Echo "Printer
connection to " & strPrinterName & " does
not exist"

objNetwork.AddWindowsPrinterConnection strPrinterName
WScript.Echo
"Installing " & strPrinterName

End If

Next

'If Exist
objNetwork.WindowsPrinterConnection strPrinterName Then
'WScript.Echo "PRINTER DOES NOT EXIST,
INSTALLING"
'objNetwork.AddWindowsPrinterConnection
strPrinterName

'ElseIf
'To Set this printer as a default
printer enable the next line
'objNetwork.SetDefaultPrinter
strPrinterName

End If
Wend
'Clean Up
Set InPutFile = Nothing
Set FileSystem = Nothing
uname = Nothing
arrname = Nothing
strPrinterName = Nothing
End Sub

'***********************************************************************************************

'*************************** Network Drive Sub
********************************************

'Can be the same as above but needs to use network_share_file variable
for the InPutFile

Sub Install_NetShares
Wscript.Echo "Running Install_NetShares"

Set Filesystem = WScript.CreateObject("Scripting.FileSystemObject")
ForReading = 1

Set InPutFile = Filesystem.OpenTextFile(network_share_file,ForReading,
False)

Wscript.Echo network_share_file

End Sub

Sub Install_Share

Wscript.Echo "Running Install_Share"
'Overwrite Flag
intRemapShare = 1

Set fso = CreateObject("Scripting.FileSystemObject")

While not InPutFile.atEndOfStream

Wscript.Echo "Running While Loop"

For Each d in fso.drives

If d.sharename <> "" Then

wscript.echo d.driveletter,
d.sharename

'Wscript.Echo "Query returned:
" & clshares.Item (i + 1)

uname = InPutFile.ReadLine()
arrname = Split (uname,",")
strDriveLetter = arrname(0)
strNetworkShare = arrname(1)

If lcase(d.sharename) =
lcase(strNetworkShare) then

Wscript.Echo "Network
Drive connection to " & strNetworkShare &
" exists, checking Re-Install Flag"

If intRemapShare = 1
Then
WScript.Echo
"Network Drive connection to " & strNetworkShare &
" exists, re-install flag SET. Removing and re-installing."
WScript.Echo
"Removing: " & strDriveLetter & ":"

objNetwork.RemoveNetworkDrive strDriveLetter & ":",True
WScript.Echo
"Drive Removed"
WScript.Echo
"Mapping " & strNetworkShare

objNetwork.MapNetworkDrive strDriveLetter & ":",
strNetworkShare

Else
WScript.Echo
"Network Drive connection to " & strNetworkShare &
" exists, but re-install flag NOT SET, discarding."

End If

Else

Wscript.Echo "Network
Drive connection to " & strNetworkShare &
" does not exist"
WScript.Echo "Mapping "
& strNetworkShare

objNetwork.MapNetworkDrive strDriveLetter & ":", strNetworkShare
WScript.Echo "Done "

End If

Else

MsgBox "Crap"

uname = InPutFile.ReadLine()
arrname = Split (uname,"")
strDriveLetter = arrname(0)
strNetworkShare = arrname(1)

Wscript.Echo "Network Drive
connection to: " & strNetworkShare &
" Does Not Exist"
WScript.Echo "Mapping " &
strNetworkShare
objNetwork.MapNetworkDrive
strDriveLetter & ":", strNetworkShare

End if

Next

Wend

msgbox "While End"
'Clean Up
Set InPutFile = Nothing
Set fso = Nothing
uname = Nothing
arrname = Nothing
strNetworkShare = Nothing
intRemapShare = Nothing
End Sub

=======================================================================

domain_admins_shares.txt:

V,\\SPICFP\DomAdmins$\BradfordC
J,\\SPICFP\NETLOGON

domain_admins_printers.txt:

\\spicprt\XPSYS_PRINT1
\\spicprt\OPS$PRINT

This is a first attempt at WSH, so forgive any silly errors.

I am trying to detect currently installed Shares and
Printers in order to avoid re-installing them unless a reInstall flag
is set.

Thanks again :)

-Chris