VB script to assign symantec antivirus parent server to multiple clients based on their default gateway
Here is a VB/WMI script to assign Symantec Antivirus parent server to multiple Clients based on their default gateway.
What this script does is to read a client list from MachineList.txt file and use Win32_NetworkAdapter and Win32_NetworkAdapterconfiguration to determine the default gateway for the clients. It will then copy GRC.DAT from the correct parent server and restart the Symantec Antivirus service on the clients.
It works for Windows server 2003 and for Windows 2000 we could use DeviceID to substitute NetConnectionID and the rest pretty much the same.
On Error Resume Next
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set InputFile = oFSO.OpenTextFile("C:\MachineList.Txt")
Do While Not (InputFile.atEndOfStream)
strComputer = InputFile.ReadLine
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
'Check for the specific NetConnectionID
Set colNetAdapters = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapter " _
& "Where NetConnectionID = " & _
"'Local Area Connection'")
For Each objNetAdapter in colNetAdapters
strMACAddress = objNetAdapter.MACAddress
‘Wscript.Echo strMACAddress
Next
Set colItems = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration")
For Each objItem in colItems
If objItem.MACAddress = strMACAddress Then
strDefaultIPGateway = objItem.DefaultIPGateway(0)
‘wscript.Echo strDefaultIPGateway
arrDefaultIPGateway = split(strDefaultIPGateway, ".")
‘wscript.Echo "The Third Octet of DefaultGateway is " & arrDefaultIPGateway(2)
Select Case arrDefaultIPGateway(2)
Case 161
strParentServer = "SERVER02"
‘Wscript.Echo strParentServer
CopyGRC
RestartNorton
Case 162
strParentServer = "SERVER03"
‘Wscript.Echo strParentServer
CopyGRC
RestartNorton
Case 163
strParentServer = "SERVER04"
‘Wscript.Echo strParentServer
CopyGRC
RestartNorton
Case 164
strParentServer = "SERVER05"
‘Wscript.Echo strParentServer
CopyGRC
RestartNorton
End Select
End If
Next
Wscript.Echo strComputer & " Is Done"
Loop
InputFile.Close
Wscript.Echo "Done"
'********************************************************************************************************************************************
'Copy GRC.dat from Parent Server to the Target Machine
Function CopyGRC
'On Error Resume Next
Const OverwriteExisting = True
Set oFSO = CreateObject("Scripting.FileSystemObject")
strSourceFile = "\\" & strParentServer & "\VPHOME\GRC.DAT"
strDestination = "\\" & strComputer & "\C$\Documents and Settings\All Users\Application Data\Symantec\Norton AntiVirus Corporate Edition\7.5\"
oFSO.CopyFile strSourceFile, strDestination, OverwriteExisting
Wscript.Echo "GRC.DAT is copied over"
End Function
'**********************************************************************************************************************************************
'**********************************************************************************************************************************************
'Restart Norton Antivirus Client
'On Error Resume Next
Function RestartNorton
Set objWMIService = GetObject("winmgmts:" & _
"{impersonationLevel=Impersonate}!\\" & strComputer & "\root\cimv2")
Set colServices = objWMIService.ExecQuery _
("Select * From Win32_Service Where name = 'Norton Antivirus Server'or name = 'Symantec Antivirus'")
For Each objService in colServices
Wscript.Echo objservice.Name
objService.StopService()
WScript.Sleep 30*1000
objService.StartService()
WScript.Echo objService.name & "has been restarted"
Next
End Function