Option Explicit
'----- Customize the following constants for your needs -----
Const HostList = "targets.txt"
Const ResultsFile = "Results.csv"
Const ScriptVersion = 1.0
Const JobSleep = 300000 'Time to sleep between jobs, in milliseconds
'----- Constant Declarations -----
Const ForReading = 1
Const ForWriting = 2
Dim sName
Dim objReg
Dim strKeyPath
Dim ValueName
Dim strValue
Const HKEY_LOCAL_MACHINE = &H80000002
Dim objFSO, strFileEntry, strPCName, wshShell, intRC, intError
Dim ListFile, LogFile, strPCDN, strRem1, strRem2, strRem3, strRem4, strRem5, strRem6
Dim objWMIService, intError, objProcess, strShell, objProgram
Dim strOS, colOperatingSystems, ObjIperatingSystem
Dim strRebootxp, strReboot2k
'----- Script Banner -----
WScript.Echo
WScript.Echo ("********************************************************")
WScript.Echo
WScript.Echo "Install Symantec Antivirus Script version " & ScriptVersion
WScript.Echo "Starting Timestamp: " & Now
WScript.Echo
Set objFSO = CreateObject("Scripting.FileSystemObject")
If (objFSO.FileExists(HostList)) Then
Set ListFile = objFSO.OpenTextFile(HostList, ForReading)
Else
wscript.echo ("ERROR: Unable to find input file " & HostList & ".")
wscript.echo (" Please make sure that the file exists and your user")
wscript.echo (" account has rights to access it.")
Set objFSO = Nothing
wscript.quit(2)
End If ' (objFSO.FileExists(HostList))
Set LogFile = objFSO.OpenTextFile(ResultsFile, ForWriting, True)
If Err.Number <> 0 Then
wscript.echo ("ERROR: Unable to initialize requested log file, " & ResultsFile & ".")
wscript.echo (" Please make sure that the path is valid.")
WScript.Echo
WScript.Echo (" Error Code was " & Err.Number & " with description: " & Err.Description & ".")
ListFile.Close
Set objFSO = Nothing
wscript.quit(2)
End If 'Err.Number <> 0
Do while ListFile.AtEndOfStream <> True
strFileEntry = ListFile.ReadLine
strPCName = Trim(strFileEntry)
If strPcName <> "" Then
InstallAntiVirus(strPCName)
End If 'strPcName <> ""
Loop 'while ListFile.AtEndOfStream <> True
LogFile.Close
ListFile.Close
set LogFile = Nothing
Set ListFile = Nothing
Set objFSO = Nothing
WScript.Echo
WScript.Echo "Ending Timestamp: " & Now
WScript.Echo ("********************************************************")
WScript.Echo
WScript.Quit
'*******************************************************************
Function InstallAntiVirus(strPCName)
WScript.Echo "Funtion InstallAntiVirus has been called"
' Based on code found at MS Scripting Site:
' [URL unfurl="true"]http://www.microsoft.com/technet/scriptcenter/scripts/os/process/procthd/pcthvb03.mspx?mfr=True[/URL]
' and
' [URL unfurl="true"]http://www.computerperformance.co.uk/vbscript/wmi_process_start.htm[/URL]
' WMI Win32_Process info
' [URL unfurl="true"]http://msdn2.microsoft.com/en-us/library/aa389388.aspx[/URL]
Dim objWMIService, intError, objProcess, strShell, objProgram, OSFind, OSFind2
strRem2 = "\\corona\VPHOME\CLT-INST\WIN32\Symantec AntiVirus.msi /qn"
On Error Resume Next
Set objWMIService=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strPCName & "\root\cimv2")
WScript.Echo "Error level is " & err & " " & err.description
If err = "429" Then
Wscript.Echo "Can't Create " & strPCName
LogFile.WriteLine strPCName & ",Can't start Copy"
Elseif err = "462" Then
WScript.Echo "Computer not Responding."
LogFile.WriteLine strPCName & ",PC not Responding to ping"
Elseif err <> 0 Then
LogFile.WriteLine err & " " & err.description
LogFile.WriteLine strPCName & ",Check for errors/"
Else
'Block to execute Rem2
Set objWMIService=GetObject("winmgmts:{impersonationLevel=impersonate}!\\"
& strPCName & "\root\cimv2")
Set objProcess = objWMIService.Get("Win32_Process")
Set objProgram = objProcess.Methods_("Create").InParameters.SpawnInstance_
objProgram.CommandLine = strRem2
Set strShell = objWMIService.ExecMethod("Win32_Process","Create",objProgram)
WScript.Echo Now & " " & strPCName & " start installer intError reports as " & intError
If Not Err = 0 Then
LogFile.WriteLine "," & Now & ",Error: Could not start Installer on," & strPCName
Else
LogFile.WriteLine "," & Now & ",Antivirus Installer Started on," & strPCName
WScript.Sleep(JobSleep)
End If 'Not Err = 0
' Your Password removal code
sName = strPCName
Set objReg = GetObject("winmgmts:\\" & sName & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\INTEL\LANDesk\VirusProtect6\CurrentVersion\AdministratorOnly\Security"
ValueName = "LockUnloadServices"
objReg.GetDWORDValue HKEY_LOCAL_MACHINE, strKeyPath, ValueName, strValue
If strValue=1 Then
objReg.setDWORDValue HKEY_LOCAL_MACHINE, strKeyPath, ValueName, 0
End If
ValueName = "UseVPUninstallPassword"
objReg.GetDWORDValue HKEY_LOCAL_MACHINE, strKeyPath, ValueName, strValue
If strValue=1 Then
objReg.setDWORDValue HKEY_LOCAL_MACHINE, strKeyPath, ValueName, 0
End If
WScript.Sleep(JobSleep)
' End Password Removal Code
'Reboot Windows 2000 or XP
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strPCName & "\root\cimv2")
WScript.Echo "Error level is " & err & " " & err.description
Set colOperatingSystems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
strOS = objOperatingSystem.Caption
Next
OSFind = instr(strOS,"xp",1)
OSFind2 = instr(strOS,"2000",1)
If OSFind <> 0 and OSFind <> "" Then
WScript.Echo strPCName & " " & strOS
'Block to execute Rebootxp
intError = 0
Set objProcess = objWMIService.Get("Win32_Process")
Set objProgram = objProcess.Methods_("Create").InParameters.SpawnInstance_
objProgram.CommandLine = strRebootxp
intError = objWMIService.ExecMethod("Win32_Process","Create",objProgram)
WScript.Echo Now & " " & strPCName & " Rebootxp intError reports as " & intError
If intError <> 0 Then
LogFile.WriteLine strPCName & "," & err.description
Else
LogFile.WriteLine Now & "," & strPCName & ",Rebootxp Started"
WScript.Sleep(JobSleep)
End If 'intError = 0
Elseif OSFind2 <> 0 and OSFind <> "" Then
'Block to execute Reboot2k
intError = 0
Set objProcess = objWMIService.Get("Win32_Process")
Set objProgram = objProcess.Methods_("Create").InParameters.SpawnInstance_
objProgram.CommandLine = strReboot2k
intError = objWMIService.ExecMethod("Win32_Process","Create",objProgram)
WScript.Echo Now & " " & strPCName & " Reboot2k intError reports as " & intError
If intError <> 0 Then
LogFile.WriteLine strPCName & "," & err.description
Else
LogFile.WriteLine Now & "," & strPCName & ",Reboot2k Started"
WScript.Sleep(JobSleep)
End If 'intError = 0
Else
LogFile.WriteLine now & "," & strPCName & ",No matching OS," & err.description
End If 'strOS
'End Reboot code
Set objWMIService = Nothing
End If
End Function 'InstallAntiVirus(strPCName)