I have compiled a script with parts from two diffrent examples from Mark D. MacLachlan and i have been testing it and it works realy good. The script checks two things.. the first it checks is if dhcp address is active and if it is it run another script and quit, if dhcp is not used it checks for logonserver beening used and then run another script and quit.
Why this then...?? Couldent i only used the last part or the first maybee..?? If i use only dhcp check, what if client using static ip?? then script 2 dont run and the user dont get drivemappings. OK if i only use logonserver... What if server1 on location1 has a lot to do or is down then server2 on location2 will answer and then the wrong script will run. So thats why i use both checks..
So whats my question then
I would appriciate if someone could take a look on the code and tell me if something is going to f*ck things upp on the clients because of some varibel. Maybe there is a way to improve the code??
Why this then...?? Couldent i only used the last part or the first maybee..?? If i use only dhcp check, what if client using static ip?? then script 2 dont run and the user dont get drivemappings. OK if i only use logonserver... What if server1 on location1 has a lot to do or is down then server2 on location2 will answer and then the wrong script will run. So thats why i use both checks..
So whats my question then
I would appriciate if someone could take a look on the code and tell me if something is going to f*ck things upp on the clients because of some varibel. Maybe there is a way to improve the code??
Code:
'==========================================================================
'
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: [URL unfurl="true"]http://www.thespidersparlor.com[/URL]
' DATE : 5/4/2005
'
'
'==========================================================================
Option EXPLICIT
'+------------------------------+
'+------------------------------+
Dim WSHShell, WSHProcess, DomainLogonServer, oReg, strKeyPath, arrSubKeys, subkey, DHCPAddress, ActiveDHCPIPAddress
On Error Resume Next
'+---------------------------------------------------------------------+
'+---------------------------------------------------------------------+
Const HKEY_LOCAL_MACHINE = &H80000002
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
".\root\default:StdRegProv")
Set WSHShell = CreateObject("Wscript.Shell")
strKeyPath = "SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
For Each subkey In arrSubKeys
DHCPAddress = WSHShell.RegRead("HKLM\" & strKeyPath & subkey & "\DhcpIPAddress")
If DHCPAddress <> "0.0.0.0" And Left(DHCPAddress,3) <> "169" Then
ActiveDHCPIPAddress = DHCPAddress
End If
Next
'+-------------------------------------------------------------------+
'+-------------------------------------------------------------------+
Select Case Left(ActiveDHCPIPAddress,7)
'location1
Case "176.16."
Call WSHShell.Run("cscript \\domain\sysvol\domain\scripts\LogonScript-1.vbs //NoLogo",0, True)
Set oReg = Nothing
Set WSHShell = Nothing
WScript.Quit
'location2
Case "176.17."
Call WSHShell.Run("cscript \\domain\sysvol\domain\scripts\LogonScript-2.vbs //NoLogo",0, True)
Set oReg = Nothing
Set WSHShell = Nothing
WScript.Quit
'location3
Case "176.18."
Call WSHShell.Run("cscript \\domain\sysvol\domain\scripts\LogonScript-3.vbs //NoLogo",0, True)
Set oReg = Nothing
Set WSHShell = Nothing
WScript.Quit
'location4
Case "176.19."
Call WSHShell.Run("cscript \\domain\sysvol\domain\scripts\LogonScript-4.vbs //NoLogo",0, True)
Set oReg = Nothing
Set WSHShell = Nothing
WScript.Quit
'location5
Case "176.20."
Call WSHShell.Run("cscript \\domain\sysvol\domain\scripts\LogonScript-5.vbs //NoLogo",0, True)
Set oReg = Nothing
Set WSHShell = Nothing
WScript.Quit
End Select
'+------------------------------------------------+
'+------------------------------------------------+
'+------------------------------+
'+------------------------------+
Set WSHShell = wscript.createObject("wscript.shell")
Set WSHProcess = WSHShell.Environment("Process")
'+---------------------------------------------+
'+---------------------------------------------+
DomainLogonServer = WSHProcess("LogonServer")
'WScript.Echo "Logon server is: "& DomainLogonServer
'+----------------------------------------------------------------+
'+----------------------------------------------------------------+
Select Case DomainLogonServer
'location1
Case "\\DC01"
Call WSHShell.Run("cscript \\domain\sysvol\domain\scripts\LogonScript-1.vbs //NoLogo",0, True)
Case "\\DC02"
Call WSHShell.Run("cscript \\domain\sysvol\domain\scripts\LogonScript-1.vbs //NoLogo",0, True)
'location2
Case "\\DC03"
Call WSHShell.Run("cscript \\domain\sysvol\domain\scripts\LogonScript-2.vbs //NoLogo",0, True)
'location3
Case "\\DC04"
Call WSHShell.Run("cscript \\domain\sysvol\domain\scripts\LogonScript-3.vbs //NoLogo",0, True)
'location4
Case "\\DC05"
Call WSHShell.Run("cscript \\domain\sysvol\domain\scripts\LogonScript-4.vbs //NoLogo",0, True)
'location5
Case "\\DC06"
Call WSHShell.Run("cscript \\domain\sysvol\domain\scripts\LogonScript-5.vbs //NoLogo",0, True)
End Select
'+---------------------+
'+---------------------+
Set WSHShell = Nothing
Set WSHProcess = Nothing
'+---------------------+
'+---------------------+
WScript.Quit