?
Solved

Script to check for and install Trend Micro

Posted on 2009-04-16
3
Medium Priority
?
989 Views
Last Modified: 2012-08-14
As I learn more about VBscript the more I figure out I can do with it.  I am attempting to create a script that will check if Trend Micro is installed, if it is then exit.  If it is not then it should check for other programs that have caused me problems with installing Trend Micro in the past and uninstall them. Finally it should install Trend Micro.  I origonally wrote this as one long script, I have since learned that is is usually better to brekup the script into Subroutines.  I am now getting an "Expected Statment" Error at the End Sub line.  Any Idea's why?  I know I'm a newbie so plz be gentle, lol
Option Explicit
Const HKLM = &H80000002
strComputer = "."
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
Set oShell = CreateObject("Wscript.Shell")
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
oReg.EnumKey HKLM,strKeyPath, aSubKeys
 
Call Check4Trend(strComputer, oReg, oShell, StrKeyPath)
 
Call IAmDone
 
Sub Check4Trend
	For Each key In aSubKeys
	'Check for Trend Micro
	If key = "OfficeScanNT" Then
		Call IAmDone
		Else Call InstallTrend
	End If
End Sub
 
Sub InstallTrend()
	Call CleanUp(strComputer, oReg, oShell, StrKeyPath)
	'Install Trend Micro Office Scan Client
	Set objWshShell = WScript.CreateObject("WScript.Shell")
	objWshShell.Run "\\piney\ofcscan\AutoPcc.exe", 1
	Call IAmDone
End Sub
 
Sub CleanUp
	For Each key In aSubKeys
	'Uninstall Adaware SE Personal
	If key = "Ad-Aware SE Personal" Then
		oReg.GetStringValue HKLM, strKeyPath & "\" & key, "UninstallString", strUninstall
		oShell.Run strUninstall & " /qn",0,True
	End If
	'Uninstall Adaware 2008
	If key = "{DED53B0B-B67C-4244-AE6A-D6FD3C28D1EF}" Then
		oReg.GetStringValue HKLM, strKeyPath & "\" & key, "UninstallString", strUninstall
		oShell.Run strUninstall,0,True
	End If
	Call InstallTrend
End Sub
 
Sub IAmDone()
Exit
End Sub
 
Exit

Open in new window

0
Comment
Question by:jring_3770
3 Comments
 
LVL 10

Accepted Solution

by:
TakedaT earned 2000 total points
ID: 24160781
Try this code.  Your biggest problem was that you forgot the "Next" statement to end the "For" statements in 2 places, in your line 14 and 31.  There were also a few other problems that I fixed.  You dont need to pass the varialbes between functions when you have them globally defined already.  And you began with "Option Explicit" which means you would need to declare every variable before you use it.  I removed that line.
Const HKLM = &H80000002
strComputer = "."
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
Set oShell = CreateObject("Wscript.Shell")
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
oReg.EnumKey HKLM,strKeyPath, aSubKeys
 
Call Check4Trend
 
Call IAmDone
 
Sub Check4Trend
	For Each key In aSubKeys
	'Check for Trend Micro
	If key = "OfficeScanNT" Then
		Call IAmDone
		Else Call InstallTrend
	End If
	Next
End Sub
 
Sub InstallTrend
	Call CleanUp
	'Install Trend Micro Office Scan Client
	Set objWshShell = WScript.CreateObject("WScript.Shell")
	objWshShell.Run "\\piney\ofcscan\AutoPcc.exe", 1
	Call IAmDone
End Sub
 
Sub CleanUp
	For Each key In aSubKeys
	'Uninstall Adaware SE Personal
	If key = "Ad-Aware SE Personal" Then
		oReg.GetStringValue HKLM, strKeyPath & "\" & key, "UninstallString", strUninstall
		oShell.Run strUninstall & " /qn",0,True
	End If
	'Uninstall Adaware 2008
	If key = "{DED53B0B-B67C-4244-AE6A-D6FD3C28D1EF}" Then
		oReg.GetStringValue HKLM, strKeyPath & "\" & key, "UninstallString", strUninstall
		oShell.Run strUninstall,0,True
	End If
 
	Next
End Sub
 
Sub IAmDone
	wscript.quit
End Sub
 

Open in new window

0
 

Author Closing Comment

by:jring_3770
ID: 31571107
Thanks alot!  That was exactly what was wrong.  I hate when I make those oversights.  Thank you for such a quick responce to my Newbie Question.
0
 

Expert Comment

by:boomerbostock
ID: 25870200
I like this cript is there anyway it can be changed to remove any other anitvirus other than Trend. I would like to check for Trend office scan V10 and if install do nothing if something else installed remove that and then install Trend.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses
Course of the Month16 days, 3 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question