Jump to content


  • 0
jamitupya

Centralized Logon Script

Question

We have a system in place that displays a Blank Screen and logo in place whilst loading your network drives and profile.

 

The reason for this is that we simply want to ensure the PC has had enough time to load all the services and applications on your computer prior to giving you your desktop.

 

This system provides that we can have a single logon script set through GPO at the root level of our domain and then INDIVIDUAL mappings per site and country.

 

This guide assumes that you have first setup Windows Server 2008 and configured it for Active Directory.

 

In a production environment please consult Technet for best practise, see below links:

 

Design Active Directory:

Document - http://technet.microsoft.com/en-us/library/bb727085.aspx

WebCast - http://msevents.microsoft.com/CUI/WebCastEventDetails.aspx?culture=en-US&EventID=1032317872&CountryCode=US

 

Implement Active Directory: http://technet.microsoft.com/en-us/library/cc778219(WS.10).aspx

 

 

 

During this script we do the following:

Detect Operating System.

if Client OS - run logon script

if Server OS - exit logon script

Check User for Mapping Distribution Group (GG-MAP-<SITECODE>)

Load <sitecode>.bat

 

 

This script is designed and built to enable easy movement of users between sites.

 

 

The folder structure is as Follows:

NETLOGON\
NETLOGON\IMG
NETLOGON\SITE
NETLOGON\SCRIPTS

 

Files:

\
logon.vbs
ifmember.exe
IMG\
logo.jpg
SCRIPTS\
SMSClientCheck.vbs
SITE\
<sitecode>.bat

 

Usage:

In each sites OU create a group GG-MAP-<siteouname>

 

GG = Global Group

MAP = Mapping Group

<siteouname> = OU Name for location

 

 

Its important that this is the format I use, and as such things will need to be modified to help. a word of warning, most of the scripts I will provide are built with a naming standard in place for large enterprises. these can be adapted for others but it is difficult.

 

My Standard is a 6 character code with the format: <CITY><BUILDING>

example: TKY123 or SYD100

 

Traditionally i use the IATA Airport Code closest to the Site AVAILABLE HERE or ..

the telco's site mnemonic

 

 

 

 

<SITECODE>.bat

@echo off
:COPY
xcopy "%logonserver%\NETLOGON\ifmember.exe" "c:\" /d /v /c /q /h /r >nul

:HIDrive
net use * /delete /yes >nul
set homedrive=\\<siteserver>\%username%$ >nul
set profiledir=\\<siteserver>\%username%$$ >nul

net use h: \\<siteserver>\%username%$ > nul
net use i: \\<siteserver>\info >nul

goto GDrives >nul

:GDrives
c:\ifmember.exe "<domain>\<sitecode>-<group>" >nul
net use g: \\<siteserver>\<group>$ >nul

:end

 

 

<logon.vbs>

'==========================================================================
'
' NAME: Logon.vbs
'
' AUTHOR: Greg G. Green
' CONTACT: diekittay[at]gmail.com
' CREATED: 14/11/2009
' LAST MODIFIED: 20/11/2009
' 
' NOTICE: If you update this and find it to be useful, credit where credits'
'         Due and please forward me a copy 
'
' COMMENT: Logon Script
'
'==========================================================================
Option Explicit
On Error Resume Next

'==========================================================================
'Get logonserver name using WSH Shell Object
'==========================================================================
Dim sLogonSrv, sUnkLS
Dim oWshShell, oWshShellEnv

sUnkLS = "Unable to determine Logonserver"

Err.Clear

Set oWshShell = WScript.CreateObject("Wscript.Shell")
Set oWshShellEnv = oWshShell.Environment("VOLATILE")
sLogonSrv = oWshShellEnv("LOGONSERVER") 
If sLogonSrv = "" Then
 sLogonSrv = sUnkLS
End If

If Err.Number <> 0 Then
 Err.Clear
 WScript.Quit
End If

'==========================================================================
'Setup user message output window using IE
'==========================================================================
Dim sTitle, sPage, sContent
Dim sScH, sScW, sFJImg, sImg,  sRndImg
Dim oDialogWindow
Set oDialogWindow = CreateObject("InternetExplorer.Application")

'Set initial window parameters
With oDialogWindow
       .FullScreen=1
       .menubar=0
       .toolbar=0
       .Resizable=0
       .statusBar=0
       .Navigate "about:blank"
End With
sScH = oDialogWindow.Height
sScW = oDialogWindow.Width

'Resize and center
With oDialogWindow
       .height=350
       .width=400
       .top=(sScH-350)/2
       .left=(sScW-400)/2
End With

]sTitle = "<INSERT COMPANY NAME>"
sPage = "JavaScript:'<html><head>" _
       & "<title>" & sTitle & "</title></head><body scroll=no bgcolor=#ffffff=></body></html>'"

       sImg = "logo.jpg"
 sFJImg = "<center><br><br><br><br><img src=""FILE:" & sLogonSrv & "\NETLOGON\IMG\" _
             & sImg & """ width=""440"" height=""272""></center><br><font color=#ED1C24>"

oDialogWindow.navigate sPage
' wait for the page to be fully initialized:
'Do
'
'  Err.Clear
'
'Loop While oDialogWindow.ReadyState<>4

 If Err.Number <> 0 Then
   Err.Clear
   WScript.Quit
 End If

' show page:
oDialogWindow.visible = 1

' now you can dynamically change content: oDialogWindow.document.body.innerHTML = "<h3><center>" & sContent & "</center></h3>"

'==========================================================================
'Determine OS using WMI
'==========================================================================
Dim sWXPP, sW2KP, sW2KS, sW2KAS, sW2KDS, sW2K3S, sW2K3W, sW2K3E, sW2K8S, sW2K8E, sWVU, sWVE, sWVP, sW7U, sW7E, sW7P, sUnkOS, sWbemOpSys
Dim oWbemServices
Dim cOperatingSystems
Dim oInstance

sWXPP = "Microsoft Windows XP Professional"
sW2KP = "Microsoft Windows 2000 Professional"
sW2KS = "Microsoft Windows 2000 Server"
sW2KAS = "Microsoft Windows 2000 Advanced Server"
sW2KDS = "Microsoft Windows 2000 Datacenter Server"
sW2K3S = "Microsoft(R) Windows(R) Server 2003, Standard Edition"
sW2K3W = "Microsoft(R) Windows(R) Server 2003, Web Edition"
sW2K3E = "Microsoft(R) Windows(R) Server 2003, Enterprise Edition"
sW2K8S = "Microsoftr Windows Serverr 2008 Standard"
sW2K8E = "Microsoftr Windows Serverr 2008 Enterprise"
sWVU = "Microsoft Windows Vista Ultimate"
sWVE = "Microsoft Windows Vista Enterprise"
sWVP = "Microsoft Windows Vista Professional"
sW7U = "Microsoft Windows 7 Ultimate"
sW7E = "Microsoft Windows 7 Enterprise"
sW7P = "Microsoft Windows 7 Professional"
sUnkOS = "OS Unknown or NOT supported"

Set oWbemServices = GetObject("winmgmts:")
Set cOperatingSystems = oWbemServices.InstancesOf("Win32_OperatingSystem")
On Error Resume Next
For Each oInstance in cOperatingSystems
 sWbemOpSys = oInstance.Caption
 If sWbemOpSys = "" Then
   sWbemOpSys = sUnkOS
 End If
Next

Select Case sWbemOpSys
 Case sWXPP
 Case sW2KP
 Case sW2KS
 Case sW2KAS
 Case sW2KDS
 Case sW2K3S
 Case sW2K3W
 Case sW2K3E
 Case sW2K8S
 Case sW2K8E
 Case sWVU
 Case sWVE
 Case sWVP
 Case sW7U
 Case sW7E
 Case sW7P
 Case Else
   sContent = sFJImg & "<h3><center>OS Not Supported:" _
            & "<br><br>" & sWbemOpSys & "</center></h3>"
   oDialogWindow.document.body.innerHTML = sContent
   WScript.Sleep 1000

   'Quit script if OS not XP, 2000, 2003, Vista, 2008 or Windows 7 until legacy OS detection is added
   oDialogWindow.Quit
   WScript.Quit
End Select

On Error GoTo 0

'==========================================================================
'Gather information from WSH Network object
'==========================================================================
Dim sUserName, sComputerName, sDomainName, sUserCN, sUserDN
Dim sFName, sLName
Dim oWshNetwork

Set oWshNetwork = WScript.CreateObject("WScript.Network")
sUserName = oWshNetwork.UserName
sComputerName = oWshNetwork.ComputerName
sDomainName = oWshNetwork.UserDomain
sUserDN = GetDN(sUserName)

On Error Resume Next
sFName = Right(sUserCN,Len(sUserCN)-InStr(sUserCN,","))
sLName = Left(sUserCN,InStr(sUserCN,",")-1)
On Error GoTo 0

'==========================================================================
'Set Greeting
'==========================================================================
Dim sHour, sGreet

sHour = DatePart("H",Now)
Select Case sHour
 Case 0,1,2,3,4,5,6,7,8,9,10,11
      sGreet = "Good Morning"
 Case 12,13,14,15,16
      sGreet = "Good Afternoon"
 Case 17,18,19,20,21,22,23
      sGreet = "Good Evening"
End Select

'Display gathered information
'WScript.Echo "User:" & vbtab & vbtab & sUserName & vbCrLf & _
'             "Computer:" & vbtab & sComputerName & vbCrLf & _
'            "Domain:" & vbtab & vbtab & sDomainName & vbCrLf & _
'             "User CN: " & vbtab & vbtab & sUserCN & vbCrLf & _
'             "User DN: " & sUserDN

sContent = sFJImg & "<h3><center>" & sGreet & " " & sFName & " " & sLName _
          & "<br>" & "Welcome to the " & sDomainName & " Domain</center></h3>"
oDialogWindow.document.body.innerHTML = sContent
WScript.Sleep 1500 

'==========================================================================
'Map Network Drives
'==========================================================================
If sWbemOpSys = sW2KS Or sWbemOpSys = sW2KAS Or sWbemOpSys = sW2KDS Or _
  sWbemOpSys = sW2K3S Or sWbemOpSys = sW2K3W Or sWbemOpSys = sW2K3E Or _
  sWbemOpSys = sW2K8S Or sWbemOpSys = sW2K8E Then
 sContent = sFJImg & "<h3><center>Server Detected, Exiting Logon Script..." _
                    & "</center></h3>"
 oDialogWindow.document.body.innerHTML = sContent
WScript.Sleep 1000 
 oDialogWindow.Quit
 WScript.Quit
Else
 Dim oUsr, oGrp
 Dim pos1, pos2, Msg
 Dim sGroup, sMnemonic

 'Change dialog text
 sContent = sFJImg & "<h3><center>Mapping Network Drives..." & "</center></h3>"
 oDialogWindow.document.body.innerHTML = sContent
WScript.Sleep 1000 

 Set oUsr = GetObject("LDAP://" & sUserDN)
 	For Each oGrp In oUsr.Groups
   	  sGroup = ucase(oGrp.Name)
    pos1 = InStr(sGroup,"GG-MAP-")

  If pos1<>0 and pos1<>"" Then
sMnemonic = UCase(Right(sGroup, 6)) 

           If sMnemonic <> "" Then
           On Error Resume Next
           Err.Clear
             oWshShell.Run sLogonSrv & "\NETLOGON\SITE\" & sMnemonic & ".bat", 0, True
             If Err.Number <> 0 Then
               Msg = MsgBox("Unable to locate script for network drive mapping. Please inform your System Administrator.", 64, "File not found (" & sMnemonic & ".bat)")
               Err.Clear
             End If
           Else
        'Msg = MsgBox("Unable to locate group for network drive mapping. Please inform your System Administrator.", 64, "Group not found")
           End If
           On Error GoTo 0
    Exit For
  End If
 Next
 Set oUsr = Nothing
 Set oGrp = Nothing
 On Error Resume Next

End If

oDialogWindow.Quit

'==========================================================================
'Obtain user distinguishedName from LoginID information using ADO
'==========================================================================
Function GetDN(logonID)
 Dim sADsPath, sQuery
 Dim oADsRootDSE, oADsDomain
 Dim oADOConn, oADOCmd, oRS

 On Error Resume Next

 GetDN="Unknown"

 sADsPath = "LDAP://RootDSE"
 Set oADsRootDSE = GetObject(sADsPath)
 Set oADsDomain = GetObject("LDAP://" & oADsRootDSE.Get("defaultNamingContext"))

 sQuery="Select sAMAccountname,cn,distinguishedname from '" & _
        oADsDomain.ADSPath & "' Where objectcategory='person' AND objectclass='user'" & _
        " AND sAMAccountName='" & logonID & "'"

 Set oADOConn=Createobject("ADODB.Connection")
 Set oADOCmd=CreateObject("ADODB.Command")
 oADOConn.Provider="ADSDSOObject"
 oADOConn.Open	

 Set oADOCmd.ActiveConnection=oADOConn
 Set oRS = oADOConn.Execute(sQuery)
 Do While Not oRS.EOF
   sUserCN = oRS.Fields("cn")
   GetDN = oRS.Fields("distinguishedname")
   oRS.movenext
 Loop
 oRS.Close
 oADOConn.Close	
 Set oADOConn=Nothing
 Set oADOCmd=Nothing
 Set oADsRootDSE=Nothing
 Set oRS=nothing
End Function

Share this post


Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Oops, forgot the SMSClientCheck.vbs

 

 

SMSClientCheck.vbs

'==========================================================================
'
' NAME: Logon.vbs
'
' AUTHOR: Greg G. Green
' CONTACT: diekittay[at]gmail.com
' CREATED: 21/06/2006
' LAST MODIFIED: 20/11/2009
' 
' NOTICE: If you update this and find it to be useful, credit where credits'
'         Due and please forward me a copy 
'
' COMMENT: Check if the SMS client is currently installed
'
'==========================================================================

Option Explicit

'Declare objects
Dim objFSO
Dim objFolder
Dim objExecmgr

Set objExecmgr = CreateObject("wscript.shell")

'Verify if execmgr.log exists.  Otherwise run capinst.exe
Set objFSO = CreateObject("Scripting.FileSystemObject")

If objFSO.FileExists("%WINDIR%\system32\CCM\Logs\execmgr.log") Then
   Set objFolder = objFSO.GetFile("%WINDIR%\system32\CCM\Logs\execmgr.log")
   objExecmgr.LogEvent 4, "SMS client already exists on this computer"
Else
   objExecmgr.LogEvent 1, "SMS client does not exist.  Executing ccmsetup.exe."
   objExecmgr.run "\\<primaryserver>\SMS_<smssitecode>\Client\ccmsetup.exe /q SMSSITECODE=<smssitecode>"

End If

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.