'==========================================================================
'
' VBScript Source File -- Created with SAPIEN Technologies PrimalSCRIPT(TM)
'
' NAME: logon.vbs
'
' AUTHOR: Craig Reiners, Mediacom
' Created On : 12.10.2002
' Last Modified: 11.10.2003
'
' COMMENT:
'
'==========================================================================
On Error Resume Next
Dim WshNetwork, asdPath, User
Dim strMappedDrives, strStatus
Dim IE, UserName
Dim Serv1, Serv2
Dim oDrives, oPrinters
' #################################################################
' ## ##
' ## Declare Servers ##
' ## ##
' #################################################################
Serv1 = "\\server1"
Serv2 = "\\server2"
' #################################################################
' ## ##
' ## Call Subs - DO NOT CHANGE ANYTHING HERE ##
' ## ##
' #################################################################
Const ADS_READONLY_SERVER = 4
Call CreateIE()' Display IE status window
Set objDomain = getObject("LDAP://rootDse")
objDC = objDomain.Get("dnsHostName")
set fso = CreateObject ("Scripting.FileSystemObject")
If fso.FileExists("c:\logon.log") Then
set USERDel = fso.GetFile ("C:\logon.log")
USERDel.Delete
End If
Set C = fso.CreateTextFile ("c:\logon.log",True)
' #################################################################
' ## ##
' ## Creates the HTML Page ##
' ## ##
' #################################################################
strStatus = "Logon Script v2.0.3 " & Date()
strStatus = strStatus & vbCRLF & "Authenticated to: " & objDC
ie.document.all.wstatus.InnerText = strMsg3
IE.Document.all.holdit.checked = False
' Get the User ID
Set WSHNetwork = WScript.CreateObject("WScript.Network")
strUser = ""
While strUser = ""
strUser = WSHNetwork.UserName
Wend
Domainname = WshNetwork.UserDomain
UserName = WSHNetwork.UserName
Set oDrives = WshNetwork.EnumNetworkDrives
Set oPrinters = WshNetwork.EnumPrinterConnections
Call FullName(DomainName,UserName)
Call UpdateCIC()
Call DivisionAll()
call main()
strStatus = strStatus & vbCRLF & "Network Logon Complete..."
ie.document.all.wstatus.InnerText = strStatus
c.writeline strStatus
' Close IE status window
'IE.Document.all.holdit.checked = True
WScript.Sleep 2000
IE.quit()
' End of logon script
' #################################################################
' ## ##
' ## SUB DECLARATIONS ##
' ## ##
' #################################################################
Public Sub Main()
'Main loop to detect group that user belongs to
adsPath = "WinNT://Mycompany/" & strUser
Set dso = GetObject("WinNT:")
Set objUser = dso.OpenDSObject(adsPath,"","", ADS_READONLY_SERVER)
For Each Prop In objUser.groups
Select Case Prop.Name
Case "Group1"
Call Group1Sub
End Select
Next 'Prop
End Sub
' #### Case Subs Below ####
' #### Everyone ####
Sub DivisionAll()
strStatus = strStatus & vbCRLF & "Member of North Central Division"
ie.document.all.wstatus.InnerText = strStatus
MapDrive "P:", Serv1 & "\public"
End Sub
' #### End Everyone ####
' #### Group1 ####
Sub Group1Sub()
strStatus = strStatus & vbCRLF & "Connecting Customer Service resources ..."
IE.Document.all.wstatus.InnerText = strStatus
ConnectPrinter Serv2,"CSSR",1
End Sub
' #### End Des Moines CSR ####
' ######################################################
' #### ####
' #### Operations Subs Below -- DO NOT CHANGE THESE ####
' #### ####
' ######################################################
Sub hold()
IE.Document.All.holdit.checked = True
WScript.Echo "Checked"
End Sub
' #### Create the IE Window ####
Sub CreateIE()
On Error Resume Next
Set IE = CreateObject("InternetExplorer.Application")
With IE
.navigate "about:blank"
.resizable=0
.height=400
.width=350
.menubar=0
.toolbar=0
.statusBar=0
.visible=1
.document.writeln("<HTML>")
.document.writeln("<head>")
.document.writeln("<title>MyCompany Network Logon</title>")
.document.writeln("</head>")
.Document.writeln("<Script Language=VBScript>")
.Document.writeln("Sub Hold()")
.Document.writeln(" document.all.holdit.checked = true")
.Document.writeln("End Sub")
.Document.writeln("</Script>")
.document.writeln("<body onclick='hold()' SCROLL='no'>")
.document.writeln("<table border='0' width='313' cellspacing='0' cellpadding='0'>")
.document.writeln(" <tr>")
.document.writeln(" <td width='311'><img border='0' src='\\mydomain\SYSVOL\mydomain.com\scripts\home_logo.gif' width='311' height='122'></td>")
.document.writeln(" </tr>")
.document.writeln(" <tr>")
.document.writeln("")
.document.writeln(" </tr>")
.document.writeln(" <tr>")
.document.writeln(" <td><font face='Tahoma'><CENTER> Welcome to the MyCompany domain!</CENTER>")
.document.writeln(" <marquee ID=scrolling width='95%' height='23'></marquee>")
.document.writeln(" </font>")
.document.writeln(" <p><font face='ARIAL'>User Name: </font>")
.document.writeln(" <font face='Tahoma' ID=Msg1></Font></p>")
.document.writeln(" <p> <font face='ARIAL'>Mapping Drives: </font>")
.document.writeln(" <font face='Tahoma' ID=Msg2></Font></p>")
.document.writeln(" <hr size='4' color=Red>")
.document.writeln(" </td>")
.document.writeln(" </tr>")
.document.writeln(" <tr>")
.document.writeln(" <td>")
.document.writeln(" <textarea rows='5' name='wstatus' cols='60' style='font-family: Arial; font-size: 8pt'></textarea></td>")
.document.writeln(" </tr>")
.document.writeln("</table>")
.document.writeln("<input type='checkbox' name='holdit'>")
.document.writeln("</body>")
.document.writeln("</html>")
Do while IE.Busy
'wait for page to load
Wscript.Sleep 2000
Loop
End With
End Sub
' #### Map Drives ####
Sub MapDrive(strDrive,strShare)
On Error Resume Next
For i = 0 to oDrives.Count - 1 Step 2
If oDrives.Item(i+1) = strShare Then
strStatus = strStatus & vbCRLF & strDrive & strShare & " already mapped."
i = oDrives.count
strMappedDrives = strMappedDrives & strDrive & " "
ie.document.all.Msg2.InnerText = strMappedDrives
Exit Sub
Else
WSHNetwork.MapNetworkDrive strDrive, strShare
If Err.Number Then
Err.Clear
WSHNetwork.RemoveNetworkDrive strDrive
WScript.Sleep 2000 ' Allow drive to finish unmapping.
WSHNetwork.MapNetworkDrive strDrive, strShare
If Err.Number <> 0 Then 'IF there is still an err then hold IE
ie.document.all.holdit.checked = True
Else
IE.Document.all.holdit.checked = False
End If
End If
End If
Next
strMappedDrives = strMappedDrives & strDrive & " "
ie.document.all.Msg2.InnerText = strMappedDrives
strStatus = strStatus & vbCRLF & strDrive & strShare & " " & Err.Description
' use to troubleshoot Err.Number
' MsgBox(Err.Number)
' MsgBox(Err.Description)
End Sub
' #### Connect Printers ####
Sub ConnectPrinter(Server, Queue, Default)
Queue = "\" & Queue
' Server = "\\" & Server
PrintPath = Server & Queue
MapCount = MapCount + 1
On error resume next
For i = 0 to oPrinters.Count - 1 Step 2
If oPrinters.Item(i+1) = PrintPath Then
i = oPrinters.Count
' Check for Default printer
If Default = 1 Then
WSHNetwork.SetDefaultPrinter(PrintPath)
strStatus = strStatus & vbCRLF & PrintPath & " (DEFAULT) Already Mapped."
Else
strStatus = strStatus & vbCRLF & PrintPath & " Already Mapped."
End If
Exit Sub
Else
WsHNetwork.AddWindowsPrinterConnection PrintPath
If Err.Number <> 0 Then 'IF there is still an err then hold IE
ie.document.all.holdit.checked = True
Else
IE.Document.all.holdit.checked = False
End If
End If
Next
' MsgBox (PrintPath)
' Check for Default printer
If Default = 1 Then
WSHNetwork.SetDefaultPrinter(PrintPath)
strStatus = strStatus & vbCRLF & PrintPath & " (DEFAULT) " & Err.Description
Else
strStatus = strStatus & vbCRLF & PrintPath & " " & Err.Description
End If
' Server = NULL
Queue = NULL
PrintPath = Null
End Sub
' #### Locate and display user's Full Name as set in AD ####
Sub FullName(DomainName,UserName)
WScript.Sleep(2000)
Set fName = GetObject("WinNT://" & domainname & "/" & UserName & ",user")
ErrNum = Err.Number
On Error GoTo 0 're-enable WSH error checking.
If ErrNum = 0 Then
ie.document.all.Msg1.InnerText = fName.FullName
Else
IE.Document.all.Msg1.InnerText = UserName & " (Full name Unavailable)"
End If
c.writeline fName.FullName
End Sub