Share This Post

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

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

Case 162

strParentServer = "SERVER03"
‘Wscript.Echo strParentServer

Case 163

strParentServer = "SERVER04"
‘Wscript.Echo strParentServer

Case 164

strParentServer = "SERVER05"
‘Wscript.Echo strParentServer

End Select

End If


Wscript.Echo strComputer & " Is Done"


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
WScript.Sleep 30*1000
WScript.Echo & "has been restarted"

End Function

Share This Post

Ying Li obtained a Master degree of Medicine in China and worked in the medical field before he came to the states in 1996. He made the career switch from troubleshooting people to troubleshooting computers after he came to the states. Not entirely a surprise there, if you know that his second preference for college is Mathematics. Ying is two times Admin Framework MVP awardee (2007-2008).His previous employment experience in the US includes UUNET, MCI WorldCom. MMC (Marsh & McLennan Companies), Merrill Lynch. He is currently employed by Related Companies as a Senior Infrastructure Engineer. He is proficient in virtually all Microsoft products (Office/Back office). His craving for efficiency naturally leads him to scripting, automation and before you know it, PowerShell! He is currently a MCSE (NT4, 2000, 2003) and MCITP Server Administrator. Ying enjoys wines and love to travel. His non work related passion is to advocate Health Living!

Leave a Reply