[Samba] universal netlogon script
johnh at primebuchholz.com
johnh at primebuchholz.com
Wed Sep 3 14:55:10 GMT 2008
Here's mine, been working great for years also. Pretty involved, does
lotsa stuff. :) Inserts stuff in databases, installs software, modifies
registry entries...
Much if this won't be of use to you, but dynamically mapping shares by
group might be.
...and yes people, I know I'm an awful VB coder. Unfortunately, I can't
write logon scripts in C. :)
-John
'*******************************************************************************************
' Logon Script
' John E.P. Hynes [02/23/2005]
'*******************************************************************************************
On Error Resume Next
'*******************************************************************************************
Set oIE = CreateObject("InternetExplorer.Application")
With oIE
.navigate "\\FS1\NETLOGON\LOGON.HTM"
.resizable=0
.height=450
.width=300
.menubar=0
.toolbar=0
.statusBar=0
.visible=1
End With
'*******************************************************************************************
Set WSHNetwork = WScript.CreateObject("WScript.Network")
strUserName = ""
While strUserName = ""
strUserName = WSHNetwork.UserName
StrDomain = WSHNetwork.UserDomain
StrHostName = WSHNetwork.ComputerName
Wend
'*******************************************************************************************
strComputer = "."
WSMAC = ""
Function GetWMIServices()
Set GetWMIServices = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer &
"\root\cimv2")
End Function
Set objWMIService = GetWMIServices()
Set colItems = objWMIService.ExecQuery("Select * from
Win32_NetworkAdapterConfiguration")
For Each objItem in colItems
IP = objItem.IPAddress
strIP = ""
MACADDR = ""
If Not IsNull(IP) And IsArray(IP) Then
For I = LBound(IP, 1) To UBound(IP, 1)
strIP = strIP & " " & IP(I)
Next
NET = Split(strIP, ".", 3)
If StrComp(NET(0), "192.168") Then
MACADDR = objItem.MACAddress
If IsNull(MACADDR) Then
MACADDR = "UNKNOWN"
End If
WSMAC = MACADDR
End If
End If
Next
'*******************************************************************************************
QueryLogon = "INSERT INTO logon(logonuser,logondateandtime,macaddress)
VALUES('" & strUserName _
& "', '" & Now & "', '" & WSMAC & "')"
Set ThisRecSet = PGSQLConnect(QueryLogon)
Set ThisRecSet = Nothing
'*******************************************************************************************
oIE.document.all.UserName.InnerText = strUserName
oIE.document.all.Domain.InnerText = strDomain
oIE.document.all.HostName.InnerText = strHostName
'*******************************************************************************************
' The Drive Map is:
' Drive Letter,
' Path,
' Group Allowed to Map to it.
Dim DriveMap(17,2)
DriveMap(0,0) = "G:"
DriveMap(0,1) = "\\FS1\APPS"
DriveMap(0,2) = "Domain Users"
DriveMap(1,0) = "K:"
DriveMap(1,1) = "\\FS1\DATA"
DriveMap(1,2) = "Domain Users"
DriveMap(2,0) = "S:"
DriveMap(2,1) = "\\FS1\SHARE1"
DriveMap(2,2) = "Domain Users"
DriveMap(3,0) = "T:"
DriveMap(3,1) = "\\TS1\SHAREDIFFERENTBOX"
DriveMap(3,2) = "Domain Users"
DriveMap(4,0) = "P:"
DriveMap(4,1) = "\\FS1\SHARE2
DriveMap(4,2) = "Domain Users"
DriveMap(5,0) = "N:"
DriveMap(5,1) = "\\FS1\SHARE3"
DriveMap(5,2) = "Group 2"
DriveMap(6,0) = "H:"
DriveMap(6,1) = "\\FS1\SHARE4"
DriveMap(6,2) = "Group 2"
DriveMap(7,0) = "E:"
DriveMap(7,1) = "\\FS1\SHARE5"
DriveMap(7,2) = "Group 3"
DriveMap(8,0) = "X:"
DriveMap(8,1) = "\\TS1\SHAREDIFFERENTBOX2"
DriveMap(8,2) = "Domain Users"
DriveMap(9,0) = "F:"
DriveMap(9,1) = "\\FS1\SHARE6"
DriveMap(9,2) = "Group 4"
DriveMap(10,0) = "I:"
DriveMap(10,1) = "\\FS1\SHARE7"
DriveMap(10,2) = "Group 5"
DriveMap(11,0) = "J:"
DriveMap(11,1) = "\\FS1\SHARE8"
DriveMap(11,2) = "Group 6"
DriveMap(12,0) = "O:"
DriveMap(12,1) = "\\FS1\SHARE9"
DriveMap(12,2) = "Group 7"
DriveMap(13,0) = "M:"
DriveMap(13,1) = "\\FS1\SHARE10"
DriveMap(13,2) = "Domain Users"
DriveMap(14,0) = "L:"
DriveMap(14,1) = "\\FS1\SHARE11"
DriveMap(14,2) = "Group 8"
Drivemap(15,0) = "Q:"
DriveMap(15,1) = "\\FS1\SHARE12"
DriveMap(15,2) = "Group 9"
Drivemap(16,0) = "R:"
DriveMap(16,1) = "\\TS3\SHARE13"
DriveMap(16,2) = "Domain Users"
Set collNetworkDrives = WSHNetwork.EnumNetworkDrives
For Drives = 0 To collNetworkDrives.Count-1
WSHNetwork.RemoveNetworkDrive collNetworkDrives(Drives*2)
Next
Set collNetworkDrives = Nothing
strMappedDrives = ""
For Index = 0 To UBound(DriveMap) Step 1
If IsMember(DriveMap(Index, 2)) Then
WSHNetwork.MapNetworkDrive DriveMap(Index,0),
DriveMap(Index,1)
strMappedDrives = strMappedDrives & " " &
DriveMap(Index,0)
End If
Next
oIE.document.all.MappedDrives.InnerText = strMappedDrives
'*******************************************************************************************
Set WshShell = WScript.CreateObject("WScript.Shell")
TimeStatus = "Now setting your clock... "
oIE.document.all.TimeStatus.InnerText = TimeStatus
WshShell.Run "NET TIME \\FS1 /SET /YES", 0, TRUE
TimeStatus = TimeStatus & "Done"
oIE.document.all.TimeStatus.InnerText = TimeStatus
Registry = "Updating your registry... "
oIE.document.all.Registry.InnerText = Registry
WshShell.Run "REGEDIT /S \\FS1\NETLOGON\PROXY.REG", 0, TRUE
WshShell.Run "REGEDIT /S \\FS1\NETLOGON\AU.REG", 0, TRUE
WshShell.Run "REGEDIT /S \\FS1\NETLOGON\LOGON.REG", 0, TRUE
WshShell.Run "REGEDIT /S \\FS1\NETLOGON\CHTML.REG", 0, TRUE
WshShell.Run "sc config Messenger start= auto", 0, TRUE
WshShell.Run "net start Messenger", 0, TRUE
Registry = Registry & "Done"
oIE.document.all.Registry.InnerText = Registry
DistFiles = "Distributing common files... "
oIE.document.all.DistFiles.InnerText = DistFiles
' WshShell.Run "CMD /C COPY \\FS1\NETLOGON\STUFF.CFG
C:\PROGRA~1\ADir\STUFF.CFG", 0, TRUE
WshShell.Run "CMD /C \\FS1\NETLOGON\MOZILLA_PREFS.BAT", 0, TRUE
If (LCase(StrHostName) <> "ss1") Then
If (LCase(StrHostName) <> "ts1") Then
WshShell.Run "CMD /C RMDIR /S /Q %WINDIR%\system32\GroupPolicy", 0,
TRUE
WshShell.Run "CMD /C XCOPY /S /E /C /H /K /Y /R /I
\\FS1\NETLOGON\GroupPolicy %WINDIR%\system32\GroupPolicy", 0, TRUE
End If
End If
DistFiles = DistFiles & "Done"
oIE.document.all.DistFiles.InnerText = DistFiles
ReqSoft = "Checking for required software... "
' Check for FireFox, Install if Missing
' Dim StrVersion
' StrVersion = WshShell.RegRead("HKLM\SOFTWARE\Mozilla\Mozilla
Firefox\CurrentVersion")
' Trim(StrVersion)
' MajMin = Split(StrVersion,".")
' If (MajMin(2) <> "7 (en-US)") Then
' WshShell.Popup "Your Mozilla version needs to be upgraded." & vbCrLf &
_
' "Click OK below, and accept all defaults during the
installation."
' WshShell.Run "CMD /C \\FS1\APPS\install\Mozilla\setup.exe", 0, TRUE
'End If
' End of Firefox Install
oIE.document.all.ReqSoft.InnerText = ReqSoft
ReqSoft = ReqSoft & "Done"
oIE.document.all.ReqSoft.InnerText = ReqSoft
'*******************************************************************************************
WScript.Sleep 2500
oIE.quit()
Set oIE = Nothing
Set WSHNetwork = Nothing
Set WshShell = Nothing
WScript.Quit
'*******************************************************************************************
Function IsMember(strGroup)
Dim objUser, objGroup, objGroupDict
Set objGroup = GetObject("WinNT://" & strDomain & "/" & strGroup &
",group")
Set objGroupDict = CreateObject("Scripting.Dictionary")
objGroupDict.RemoveAll
For Each objUser In objGroup.Members
objGroupDict.Add objUser.Name, "-"
Next
IsMember = objGroupDict.Exists(strUserName)
Set objUser = Nothing
Set objGroup = Nothing
Set objGroupDict = Nothing
End Function
'*******************************************************************************************
Function PGSQLConnect(strSQL)
Set conn = CreateObject("ADODB.Connection")
conn.Open
"Driver={PostgreSQL};UID=logon-admin;PWD=;Server=ds1;Database=logons"
Set rst = CreateObject("ADODB.Recordset")
rst.Open strSQL, conn
rst.ActiveConnection = Nothing
conn.Close
Set conn = Nothing
Set PGSQLConnect = rst
Set rst = Nothing
End Function
'*******************************************************************************************
--
This e-mail is intended only for the named person or entity to which it
is addressed and contains valuable business information that is
privileged, confidential and/or otherwise protected from disclosure.
Dissemination, distribution or copying of this e-mail or the information
herein by anyone other than the intended recipient, or an employee, or
agent responsible for delivering the message to the intended recipient,
is strictly prohibited. All contents are the copyright property of the
sender. If you are not the intended recipient, you are nevertheless
bound to respect the sender's worldwide legal rights. We require that
unintended recipients delete the e-mail and destroy all electronic
copies in their system, retaining no copies in any media. If you have
received this e-mail in error, please immediately notify us by calling
our Help Desk at (603) 433-1143, or e-mail to it at primebuchholz.com.
We appreciate your cooperation.
More information about the samba
mailing list