Saturday, June 21, 2008

NICE LOGON SCRIPT

Download this scriptClick here to print the script.


Author: Grant Ardern

Description:

Logon script proven to actually lower workstation cost of ownership by standardizing environment without the limitations of desktop lockdowns.

Script:

'-------------------
'VBS LOGON SCRIPT - If Possible Consult Domain Admin Before Editing This Script...
'-------------------
'Original script by Grant Ardern ext 8433 mob 025 871 827 email grant@digitalmuscle.net
'-------------------
' Defining Variables and Initialising Scripting Objects
'-------------------
Const SOURCE = "\\ServerName\NETLOGON\virusdat4"
Const TARGET_NT = "C:\Program Files\Network Associates\VirusScan NT"
Const ForReading = 1, ForWriting = 2, ForAppending = 8

Dim WSHNetwork
Dim WshShell
Dim WshSysEnv
Dim WshProcessEnvironment
Dim UserObj
Dim objTimer
Dim strUserID 'User Name
Dim strWorkstation
Dim sNIC, sMan
Dim iCount
Dim strDomain
Dim strOS, strTarget, strSource

If err <> 0 Then
   Wscript.echo "Login Script Failed - Contact IT, ext 8453"
End If

Set WSHNetwork = WScript.CreateObject("WScript.Network")
Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshProcessEnvironment = WshShell.Environment("Process")
Set FileSysObj = CreateObject("Scripting.FileSystemObject")
Set LoginBox = CreateObject("Loginscreen.Main")
Set WshSysEnv = WshShell.Environment
Set DomainObj = GetObject("WinNT://DomainName")

strDomain = "DomainName"

on error resume next

Do
 strUserID = WSHNetwork.UserName
 strWorkstation = WSHNetwork.ComputerName
Loop Until strUserID <> ""


Set UserObj = GetObject("WinNT://" & strDomain & "/" & strUserID)

'***Initialise Groups
     Dim UserGroups
     Dim GroupObj
     UserGroups=""
     For Each GroupObj In UserObj.Groups
          UserGroups=UserGroups & "[" & GroupObj.Name & "]"
     Next

'*** Initialising LoginBox
LoginBox.Start
LoginBox.SetImage("\\ServerName\netlogon\PH_login.bmp")
LoginBox.SetTitle("Company Name Ltd")
LoginBox.SetWelcomeMessage("Running Logon Script For Pacific Health Ltd.,Tauranga...")
LoginBox.SetWaitMessage("Please wait while you are being logged onto the network...")

'-------------------
' General Logon Processes - (Specifics Executed By Procedures & Functions)
'-------------------

LoginBox.Pbar(10)
LoginBox.SetDisplayMessage ("Welcome " & strUserId & vbCrLF)

LoginBox.Pbar(20)
Text = "Mapping G: Drive To Group Shares"
LoginBox.SetDisplayMessage(Text)
KillDrive("G:")
MapDrive "G:","\\ServerName\grpshare"
LoginBox.Pbar(30)

Text = Text & vbcrlf & "Mapping H: Drive To Home Directory"
LoginBox.SetDisplayMessage(Text)
KillDrive("H:")
MapDrive "H:","\\ServerName\" & strUserID
LoginBox.Pbar(40)


If InGroup("IT") Then
Text = Text & vbcrlf & "Mapping I: Drive To Installs Directory"
LoginBox.SetDisplayMessage(Text)
KillDrive("I:")
MapDrive "I:","\\ServerName\Installs"
LoginBox.Pbar(45)
End If

'** Temp Change for comrad (needs to map k: \\foxtrot\comrad\comrad)
'I have done this in the initial script using a net use stmt as this fails)
'**

'If strOS = "Windows_NT" Then
'     If InGroup("Domain Users") Then
'          Text = Text & vbcrlf & "Mapping K: Drive To ComRad"
'          LoginBox.SetDisplayMessage(Text)
'          KillDrive("K:")
'          MapDrive "K:","\\ServerName\Comrad\"
'          LoginBox.Pbar(45)
'     End If
'End If

If InGroup("DBAccess") Then
Text = Text & vbcrlf & "Mapping L: Drive To Database Directory"
LoginBox.SetDisplayMessage(Text)
KillDrive("L:")
MapDrive "L:","\\ServerName\DBAccess"
LoginBox.Pbar(50)
End If

If InGroup("TESTING") Then
Text = Text & vbcrlf & "Mapping M: Drive To Mt on Oscar"
LoginBox.SetDisplayMessage(Text)
KillDrive("M:")
MapDrive "M:","\\Oscar\Mt"
LoginBox.Pbar(55)
End If

If InGroup("ANSOS") Then
Text = Text & vbcrlf & "Mapping M: Drive To Ansos"
LoginBox.SetDisplayMessage(Text)
KillDrive("M:")
MapDrive "M:","\\whiskey\ansos"
LoginBox.Pbar(55)
End If

If InGroup("Domain Admins") Then
Text = Text & vbcrlf & "Mapping N: Drive To ServerName\Netlogon"
LoginBox.SetDisplayMessage(Text)
MapDrive "N:","\\ServerName\Netlogon"
LoginBox.Pbar(60)
End If

If InGroup("IT") Then
Text = Text & vbcrlf & "Mapping O: Drive To Quetzal Directory"
LoginBox.SetDisplayMessage(Text)
KillDrive("O:")
MapDrive "O:","\\106180\Quetzal"
LoginBox.Pbar(65)
End If

If InGroup("COMMUNITY") Then
Text = Text & vbcrlf & "Mapping P: Drive To CMS"
LoginBox.SetDisplayMessage(Text)
KillDrive("P:")
MapDrive "P:","\\ServerName\cms"
LoginBox.Pbar(65)
End If

If InGroup("MATERNITY") Then
Text = Text & vbcrlf & "Mapping P: Drive To Terranova"
LoginBox.SetDisplayMessage(Text)
KillDrive("P:")
MapDrive "P:","\\ServerName\tnova"
LoginBox.Pbar(65)
End If

If InGroup("pharmasc") Then
Text = Text & vbcrlf & "Mapping P: Drive To Ascribe"
LoginBox.SetDisplayMessage(Text)
KillDrive("P:")
MapDrive "P:","\\ServerName\ac_live"
KillDrive("N:")
MapDrive "N:","\\ServerName\ascibe"
LoginBox.Pbar(65)
End If

If InGroup("AFFINITY") Then
Text = Text & vbcrlf & "Mapping P: Drive To Mantrack"
LoginBox.SetDisplayMessage(Text)
KillDrive("P:")
MapDrive "P:","\\whiskey\affinity$"
LoginBox.Pbar(65)
End If


If InGroup("telephonists") Then
Text = Text & vbcrlf & "Mapping W: Drive To Winpage"
LoginBox.SetDisplayMessage(Text)
KillDrive("W:")
MapDrive "W:","\\basekitnt\winpage"
LoginBox.Pbar(65)
End If

If InGroup("Domain Admins") Then
Text = Text & vbcrlf & "Mapping P: Drive To ServerName Apps"
LoginBox.SetDisplayMessage(Text)
KillDrive("P:")
MapDrive "P:","\\ServerName\apps"
LoginBox.Pbar(65)
End If

If InGroup("PAYROLL") Then
Text = Text & vbcrlf & "Mapping Q: Drive To Decision Group"
LoginBox.SetDisplayMessage(Text)
KillDrive("Q:")
MapDrive "Q:","\\Oscar\Decisiongroup"
LoginBox.Pbar(65)
End If

If InGroup("3M") Then
Text = Text & vbcrlf & "Mapping R: Drive To 3M Encoder"
LoginBox.SetDisplayMessage(Text)
KillDrive("R:")
MapDrive "R:","\\ServerName\encoder"
LoginBox.Pbar(65)
End If

If strUserID="GRANT" Then
Text = Text & vbcrlf & "Mapping S: Drive To Std Desktop"
LoginBox.SetDisplayMessage(Text)
KillDrive("S:")
MapDrive "S:","\\build\StdDsktp"
LoginBox.Pbar(65)
End If

Text = Text & vbcrlf & "Checking Virus Files Are Up To date..."
LoginBox.SetDisplayMessage(Text)
VirusFilesCheck
LoginBox.Pbar(70)


If Not InGroup("SpecialNetwork") Then
CheckNetwork
UpdateRegistry
Text = Text & vbcrlf & "Checking Registry & Network settings Are Correct"
LoginBox.SetDisplayMessage(Text)
End If


Text = Text & vbcrlf & "Performing Miscellaneous Corrections"
LoginBox.SetDisplayMessage(Text)
MiscellaneousFixes
LoginBox.Pbar(90)

Set SuccessLog =
FileSysObj.OpenTextFile("\\ServerName\logfile$\NT_Logons.txt",
ForAppending, True, TristateFalse)
SuccessLog.WriteLine(int(now()) &" , " & strUserID & " , " &
strWorkstation & " , "& time & vblf)
SuccessLog.Close

LoginBox.Pbar(100)
on error resume next

'LoginBox.NoPBar
Set objTimer = CreateObject ("TimeObject.Time")
objTimer.Timer (1) 'Wait 1 seconds

LoginBox.Kill


Set LoginBox = nothing

'-------------------
'----------Sub-Procedures---------

'-------------------
' Sub: Disconnects Network Drives
'-------------------
Sub KillDrive(strdrive)

On Error Resume Next
If FileSysObj.DriveExists(strDrive) = true then
WshNetwork.RemoveNetworkDrive strDrive

End Sub
'-------------------
' Sub: Drive Mapping Routine
'-------------------
Sub MapDrive( strDrive, strShare )

     Dim Path
     If InStr(strShare,"\") then
          Path=strShare
     Else
          Path="\\" & Authsvr & "\" & strShare
     End If

     ' Map drive
     On Error Resume Next
     WSHNetwork.MapNetworkDrive strDrive, Path

     ' End Sub result
     If Err.Number <> 0 Then WriteErr( strUserID & ": Mapping " & strDrive & " to " & Path & " " & Err.Description & " " & Now() )
End Sub
'-------------------
' Function: InGroup
'-------------------
Function InGroup(strGroup)
     InGroup=False
     If InStr(UserGroups,"[" & strGroup & "]") Then
               InGroup=True
     End If
End Function
'-------------------
' Virus File Maintenance
'-------------------
Sub VirusFilesCheck
On error resume next
 GetOS
  If strOS = "Windows_NT" Then
     If IsFileOlder(TARGET_NT & "\SCAN.DAT", SOURCE & "\SCAN.DAT") Then
               WshShell.Run "net stop " & Chr(34) & "Network Associates McShield" & Chr(34), 0, TRUE
               CopyDirFiles SOURCE, TARGET_NT
               WshShell.Run "net start " & Chr(34) & "Network Associates McShield" & Chr(34), 0, TRUE
               'Wscript.Echo "Virus Files Updated!"
     End If
  End If
End Sub
'-------------------
' Sub: Return OS Type
'-------------------
Sub GetOS

     strOS = WshSysEnv("OS")

End Sub

'-------------------
' Function: File Creation Date Comparison
'------------------
Function IsFileOlder(filespec1, filespec2)
     Dim f1, f2, strTargetDate, strSourceDate, bExists

     bExists = TRUE
     If Not FileSysObj.fileExists(filespec1) Then
          strPrompt = "Target file:" & vbLf & vbLf & filespec1 & vbLf & vbLf &_
                                         "NT Virus Scanner ver 4 Not Installed! Click OK & Call IT-ext 8453"
          bExists = FALSE
     ElseIf Not FileSysObj.fileExists(filespec2) Then
          strPrompt = "Source file:" & vbLf & vbLf & filespec2 & vbLf & vbLf &_
                                         "Virus Files Don't Exist! Please Call IT-ext 8453"
          bExists = FALSE
     End If

     If bExists = FALSE Then
          strTitle = "File Comparison Error!"
          MsgBox strPrompt, vbCritical, strTitle
          'Wscript.Quit
          Exit Function
     End If

     Set f1 = FileSysObj.GetFile(filespec1)
     Set f2 = FileSysObj.GetFile(filespec2)
     strTargetDate = f1.DateLastModified
     strSourceDate = f2.DateLastModified

     If strTargetDate < strSourceDate Then
          IsFileOlder = TRUE
               Else
          IsFileOlder = FALSE

     End If

End Function
'-------------------
' Function: CopyFile
'-------------------

Sub CopyFile(strSource, strDest)
     Dim lfsObject
     Dim Source

     On Error Resume Next
     Set lfsObject = CreateObject("Scripting.FileSystemObject")
     Set Source = lfsObject.GetFile(strSource)

      Source.Copy strDest
     Set lfsObject = nothing

End Sub

'-------------------
' Sub: Copy Files From Directory
'-------------------
Sub CopyDirFiles(strSourceDir, strTargetDir)
     Dim lfsObject, lFileList, lFolder, lFile

     On Error Resume Next
     Set lfsObject = CreateObject("Scripting.FileSystemObject")
     Set lFolder = lfsObject.GetFolder(SOURCE)
     Set lFileList = lFolder.Files


     For Each lFile in lFileList
          lfsObject.CopyFile SOURCE & "\" & lFile.Name, TARGET_NT & "\" & lFile.Name
     Next


End Sub

'-------------------

' Standard Registry Changes and Maintenance
'-------------------
Sub UpdateRegistry
     'Clear log-out error
     'WSHShell.RegDelete "HKLM\Software\Microsoft\Windows\CurrentVersion\ProfileList\" & strUserID & "\BadLocal"



     'Clear last user
'     WSHShell.RegWrite "HKLM\Network\Logon\username", ""

On error resume next

If Not InGroup("OfflineUsers") Then
     WSHShell.RegWrite "HKCU\Software\Microsoft\Office\8.0\Outlook\OST\NoOst", 0, "REG_DWORD"
End If

     'WSHShell.RegWrite "HKCU\Software\Microsoft\Office\8.0\Outlook\Today\URL", "http://pacentral/index.html"
     'WSHShell.RegWrite "HKCU\Software\Microsoft\Office\9.0\Outlook\Today\URL", "http://pacentral/index.html"
     WSHShell.RegWrite "HKCU\Software\Microsoft\Internet Explorer\Main\Start Page","http://pacentral/index.html"
     WSHShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\LinkResolveIgnoreLinkInfo", 1, "REG_DWORD"
     WSHShell.RegWrite "HKCU\Software\Microsoft\Internet Explorer\Main\Search Page","http://10.0.1.249/welcome.html"
     WSHShell.RegWrite "HKCU\Control Panel\Keyboard\Initial\KeyboardIndicators", "2"
     WSHShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Cache", "%Windir%\Temporary Internet Files"
     WSHShell.RegWrite "HKLMSoftware\Microsoft\Windows\CurrentVersion\AppInstallPath", "%logonserver%\Netlogon\domainadmin\apps.ini"
     WSHShell.RegWrite "HKLM\Software\Microsoft\Clients\Mail\(Default)", "Microsoft Outlook"
     WSHShell.RegWrite "HKCU\Software\Policies\Microsoft\Windows\System\ExcludeProfileDirs", "Temporary Internet Files;Temp;History"
     WSHShell.RegWrite "HKCU\Software\Microsoft\Windows NT\Current Version\Winlogon\RunLogonScriptSync", "1"
     WSHShell.RegWrite "HKCU\Software\Microsoft\Windows NT\Current Version\Winlogon\ExcludeProfileDirs", "Local Settings\Application Data\Microsoft\Outlook"
     WSHShell.RegWrite "HKLM\Software\McAfee\VirusScan\McShield\CurrentVersion\szDefProgExts", "EXE COM DOC DOT XL? MD? VXD 386 SYS BIN RTF OBD DLL SCR OBT PP? POT OLE SHS MPP MPT XTP XLB CMD OVL DEV VBS ADT CBT CLA CPL CSC DRV HTM HTT JS MSO OV?"
     WSHShell.RegWrite "HKLM\Software\McAfee\VirusScan\McShield\CurrentVersion\szProgExts", "EXE COM DOC DOT XL? MD? VXD 386 SYS BIN RTF OBD DLL SCR OBT PP? POT OLE SHS MPP MPT XTP XLB CMD OVL DEV VBS ADT CBT CLA CPL CSC DRV HTM HTT JS MSO OV?"

If Not InGroup("SpecialRegistry") Then
     WSHShell.RegWrite "HKCU\Software\Microsoft\ClipArt Gallery\3.0\ConcurrentDatabases\Office97 Clipart","G:\Shared\Clipart\Office.cag"
     WSHShell.RegWrite "HKCU\Software\Microsoft\ClipArt Gallery\3.0\ConcurrentDatabases\Office97 Multimedia Clipart","G:\Shared\Clipart\mmedia.cag"
     WSHShell.RegWrite "HKCU\Software\Microsoft\ClipArt Gallery\3.0\ConcurrentDatabases\Office97 Photos Clipart","G:\Shared\Clipart\photos.cag"
     WSHShell.RegWrite "HKCU\Software\Microsoft\ClipArt Gallery\3.0\ConcurrentDatabases\Office97 Popular Clipart","G:\Shared\Clipart\pop97.cag"
     WSHShell.RegWrite "HKCU\Software\Microsoft\ClipArt Gallery\3.0\ConcurrentDatabases\Office97 PowerPoint Clipart","G:\Shared\Clipart\powerpnt.cag"
     WSHShell.RegWrite "HKCU\Software\Microsoft\ClipArt Gallery\3.0\ConcurrentDatabases\Office97 Screen Beans Clipart","G:\Shared\Clipart\scrbeans.cag"
     WSHShell.RegWrite "HKCU\Software\Microsoft\Office\8.0\Word\Options\DOC-PATH", "H:\"
     WSHShell.RegWrite "HKCU\Software\Microsoft\Office\8.0\Word\Options\PICTURE-PATH", "G:\Shared\Clipart"
     WSHShell.RegWrite "HKCU\Software\Microsoft\Office\8.0\Common\FileNew\LocalTemplates\","C:\Pr ogram Files\Microsoft Office\Templates"
     WSHShell.RegWrite "HKCU\Software\Microsoft\Office\8.0\Common\FileNew\SharedTemplates\","G:\Shared\Templates\"
     WSHShell.RegWrite "HKCU\Software\Microsoft\Office\8.0\PowerPoint\Recent Folder List\Default", "H:\"
     WSHShell.RegWrite "HKCU\Software\Microsoft\Office\8.0\Excel\Microsoft Excel\DefaultPath", "H:\"
     WSHShell.RegWrite "HKCU\Software\Microsoft\Office\8.0\Excel\Microsoft Excel\Options3", 44, "REG_DWORD"
     WSHShell.RegWrite "HKCU\Software\Microsoft\Office\8.0\Access\Settings\Default DataBase Directory", "L:\"
     WSHShell.RegWrite "HKLM\SOFTWARE\Microsoft\Shared Tools\Proofing Tools\Custom Dictionaries\1", "\\ServerName\grpshare\Shared\Dictionaries\Medical1.dic"
     WSHShell.RegWrite "HKLM\SOFTWARE\Microsoft\Shared Tools\Proofing Tools\Custom Dictionaries\2", "\\ServerName\grpshare\Shared\Dictionaries\Medical2.dic"
     WSHShell.RegWrite "HKLM\SOFTWARE\Microsoft\Shared Tools\Stationery\Stationery Folder", "\\ServerName\grpshare\Shared\Stationery"
     WSHShell.RegWrite "HKLM\SOFTWARE\Microsoft\Shared Tools\Stationery\Backgrounds Folder", "\\ServerName\grpshare\Shared\Stationery"

End If

     'Office AutoCorrect Lists
     'WSHShell.RegWrite "HKCU\Software\Microsoft\Office\8.0\Common\AutoCorrect\Path","G:\Shared\Dictionaries\autocorrect.acl"

End Sub


'-------------------
' Network Settings Checks & Updates - Hosts file, DCHP, Gateways, Etc...
'-------------------
Sub CheckNetwork

' Set the DCHP service to autostart
If Not InGroup("SpecialNetwork") Then
     'WSHShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Services\DHCP\Start", 2
     WSHShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Services\TCPIP\Parameters\DhcpDomain", "DNSdomain.co.nz"
     WSHShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Services\TCPIP\Parameters\DhcpNameServer", "10.0.7.7 10.0.7.1"
     WSHShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Services\TCPIP\Parameters\Domain", "DNSdomain.co.nz"
     WSHShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Services\TCPIP\Parameters\NameServer", "10.0.1.249"
     WSHShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Services\TCPIP\Parameters\IPEnableRouter", 1, "REG_DWORD"
     WSHShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Services\TCPIP\Parameters\SearchList", "DNSdomain.co.nz"
End If

' Get Network card
On Error Resume Next
iCount = 1
Do
  sNIC = WSHShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\" & iCount & "\ServiceName")
  sMan = WSHShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\" & iCount & "\Manufacturer")
  ' Skip the Async and NDIS services
  If sMan <> "Microsoft" And Err.Number = 0 Then
     ' Call SetNIC
  End If
  iCount = iCount + 1
Loop Until Err.Number <> 0

' Clear the error
Err.Clear

End Sub
'*******************
Sub SetNIC
  Dim iTest
  ' Set the NIC service to use DHCP
  sNIC = "HKLM\SYSTEM\CurrentControlSet\Services\" & sNIC &"\Parameters\TCPIP\"
  iTest = WSHShell.RegRead(sNIC & "EnableDHCP")
  If iTest = 0 Then
    WSHShell.RegWrite sNIC & "EnableDHCP", 1, "REG_DWORD"
    WSHShell.RegWrite sNIC & "IPAddress", "0.0.0.0", "REG_MULTI_SZ"
    WSHShell.RegWrite sNIC & "SubnetMask", "0.0.0.0", "REG_MULTI_SZ"
  End If
End Sub

'-------------------

' Miscellaneous Fixes, File Copies Etc...
'-------------------

Sub MiscellaneousFixes
On error resume next

'Disabling VBS.Freelink Virus
     If WSHShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\Rundll") = "RUNDLL.VBS" then
          WSHShell.RegDelete "HKCU\Software\Microsoft\Windows\Current Version\Run\Rundll"
     End If

If strOS = "Windows_NT" Then
'CopyFile "\\ServerName\Netlogon\domainadmin\winnt256.bmp","C:\WinNT\winnt256.bmp"
CopyFile "\\ServerName\Netlogon\domainadmin\oemlogo.bmp","C:\WinNT\system32\oemlogobmp"
CopyFile "\\ServerName\Netlogon\domainadmin\oeminfo.ini","C:\WinNT\system32.ini"
End If

If InGroup("administrators") Then
    CopyFile "\\ServerName\Netlogon\domainadmin\Hosts","C:\WinNT\System32\Drivers\Etc"
End If

End Sub

 

 

No comments: