Sign in to follow this  
Followers 0
AntiVirusGuy

multiple variable

26 posts in this topic

here is what I am trying to do

$MYAPP = "Trend" or "McAfee" or "Norton" ; I know OR will not work but this is what I need to do

$UNINSTALLSTRING = GetUninstallString($MYAPP)

any idea how to specify multiple strings?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Well you will need an If to check for if the different programs exists...

Like...

If FileExists("PathToInstallDirForNorton\Norton.exe") Then $MYAPP = "Norton"
If FileExists("PathToInstallDirForTrend\Trend.exe") Then $MYAPP = "Trend"
If FileExists("PathToInstallDirForMcAfee\McAfee.exe") Then $MYAPP = "McAfee"

Edit:

There's probably other ways to detect if they are installed.. Maybe using RegRead() to read some entry from the system registry...

Defining multiple variables can be done by separating them with a , sign

ie.

Dim $Var1, $Var2, $Var3

Edited by FreeFry

Share this post


Link to post
Share on other sites

Ultimately, I think you'll end up having to check some sort of condition.

If something then

$myapp = this

elseif something then

etc etc.

You'll probably have to get your condition by taking a peek in the users registry.

Share this post


Link to post
Share on other sites

????

Global $MYAPP[3] = ["Trend","McAfee","Norton"]
Global $UNINSTALLSTRING[3]
For $i = 0 To UBound($MYAPP) - 1
    $UNINSTALLSTRING[$i] = GetUninstallString($MYAPP)
Next

Share this post


Link to post
Share on other sites

I am scanning the registry for any installed antivirus the problem is companies like Norton and Mcafee and Trend do not use the key word antivirus so I am scanning the uninstall keys for all potential programs. I want to keep it confined to the registry. any thoughts? As allways thank you, your expertise is greatly appreciated.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

One way would be to map where all anti-viruses gets installed to(at least those that you support).

Then use FileExist() to check if they are installed or not

Another way would be to find out any registry entries they make when they are installed, and just RegRead those to check if they are installed. Your choice.

Edited by FreeFry

Share this post


Link to post
Share on other sites

this is what I get

Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

$UNINSTALLSTRING[$i] = GetUninstallString($MYAPP)

^ ERROR

Share this post


Link to post
Share on other sites

I need to support all products all versions. all the installed apps are in [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall]

I can currently scan for a single name but I need to be able to look for all names

Share this post


Link to post
Share on other sites

If you would provide us with your code it might be a little easier to help you.

Share this post


Link to post
Share on other sites

;here it is many people have helped me I don't pretend to half understand it as I do not have a programming background

$MYAPP = "Trend"

$UNINSTALLSTRING = GetUninstallString($MYAPP)

$Dispaly = GetDispalyName($MYAPP)

;

if $Dispaly = "0" then

MsgBox(64, "Not Found", "No existing Anti Virus found", 3)

Else

#Region --- CodeWizard generated code Start ---

;MsgBox features: Title=Yes, Text=Yes, Buttons=OK and Cancel, Icon=None

If Not IsDeclared("iMsgBoxAnswer") Then Dim $iMsgBoxAnswer

$iMsgBoxAnswer = MsgBox(36, 'Found:', $Dispaly & @CRLF & 'Has been Found, do you want to uninstall it?')

Select

Case $iMsgBoxAnswer = 6 ;OK

Runwait($UNINSTALLSTRING)

Case $iMsgBoxAnswer = 7 ;Cancel

Exit

EndSelect

Endif

#EndRegion --- CodeWizard generated code End ---

TrayTip("Installing", "New Antivirus", 30, 1)

RunWait(@TempDir & "\newav.exe")

Sleep(2000)

ProcessWaitClose("setup.exe")

TrayTip("", "", 0)

MsgBox(64,"Success!", "Newav has Installed please reboot your computer", 4)

;If Not @error Then Run($UNINSTALLSTRING)

Func GetUninstallString($app)

Local $key = "HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall"

$i = 0

While 1

$i += 1

Local $subkey = RegEnumKey($key, $i)

If @error Then ExitLoop

;If @error Then ContinueLoop

Local $displayname = RegRead($key & "\" & $subkey,"DisplayName")

If StringInStr($displayname, $app) Then Return RegRead($key & '\' & $subkey, 'UninstallString')

WEnd

Return SetError(1, 0, 0)

EndFunc

Func GetDispalyName($app)

Local $key = "HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall"

$i = 0

While 1

$i += 1

Local $subkey = RegEnumKey($key, $i)

If @error Then ExitLoop

;If @error Then ContinueLoop

Local $displayname = RegRead($key & "\" & $subkey,"DisplayName")

If StringInStr($displayname, $app) Then Return $displayname

WEnd

Return SetError(1, 0, 0)

EndFunc

Share this post


Link to post
Share on other sites

It would also be cool if it went in a loop in case the user has more than one product installed but I need to work this out first

Share this post


Link to post
Share on other sites

#include <array.au3>

Dim $regArray[1], $avArray[4] = ['trend', 'mcafee', 'norton', 'avg']  ;stick your keywords per av software here
$i = 0

While 1
    $i += 1
    $regval = RegEnumKey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", $i)
    If @error <> 0 then ExitLoop
    _ArrayAdd($regArray, $regval)
WEnd

For $i = 1 To UBound($regArray) - 1
    For $x = 0 To UBound($avArray) - 1
        If StringInStr($regArray[$i], $avArray[$x]) Then
            $avApp = $avArray[$x]
            ExitLoop 2
        EndIf
    Next
Next

MsgBox(0, '', $avApp)

Share this post


Link to post
Share on other sites

this is what I get

(22) : ==> Variable used without being declared.:

MsgBox(0, '', $avApp)

MsgBox(0, '', ^ ERROR

just to make sure you know what I am trying to do. I am searching the display name then if I find a match I want to grab it's uninstall key like the above code. Again thank you so much for all the help

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Dim $SupportedApps = "Trend,McAfee,Norton,Messenger,Winamp,Windows"  ; Add more AV's here, separate them with a comma (,)
Dim $Exlude = "My Antivirus" ; seriously, you need a better name :P


Dim $MyApps = StringSplit($SupportedApps, ",")
Dim $InstalledAppsCount = 1
Dim $Found = 0

TrayTip("Scanning...", "Scanning registry for installed AntiVirus(es).", 5)

While 1
   
    $SubKey = RegEnumKey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", $InstalledAppsCount)
    If @error Then ExitLoop
   
    $DisplayName = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $SubKey, "DisplayName")
    $Uninstallstring = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $SubKey, "UninstallString")
   
    For $i = 1 To $MyApps[0]
        
        If $DisplayName = $Exlude Then
            ExitLoop
        ElseIf StringInStr($DisplayName, $MyApps[$i]) Then
           
            $Found += 1
           
            If MsgBox(36, 'Found:', $DisplayName & @CRLF & 'Has been Found, do you want to uninstall it?') = 6 Then
                RunWait($Uninstallstring)
            Else
                ContinueLoop
            EndIf
           
        EndIf
       
    Next
   
    $InstalledAppsCount += 1
   
WEnd

If Not $Found Then
    MsgBox(64, "Not Found", "No existing Anti Virus found", 3)
Else
    MsgBox(64, "Found", "Found " & $Found & " installed antivirus.")
EndIf

TrayTip("Installing", "New Antivirus", 30, 1)
RunWait(@TempDir & "\newav.exe")
ProcessWait("setup.exe")
ProcessWaitClose("setup.exe")
TrayTip("", "", 0)
MsgBox(64,"Success!", "Newav has Installed please reboot your computer", 4)

Hope this works for you. :P

Edited by FreeFry

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

the only thing is the AV count came out at 177 when I had two installed.

This seemed to cure it

MsgBox(64, "Found", "Found " & $InstalledAppsCount -176 & " installed antivirus.")

also to add another product I did this

Dim $MyApps[4][2] = [["Trend"], ["nod32"], ["Norton"], ["symantec"]]

is this correct?

Edited by ssebrownatcolby

Share this post


Link to post
Share on other sites

this is what I get

(22) : ==> Variable used without being declared.:

MsgBox(0, '', $avApp)

MsgBox(0, '', ^ ERROR

just to make sure you know what I am trying to do. I am searching the display name then if I find a match I want to grab it's uninstall key like the above code. Again thank you so much for all the help

The error is if it doesn't find a match... you can do your own error checking. :P Change the message box to the below and you'll see how the uninstall string is returned.

MsgBox(0, '', 'your search string: ' & $avApp & @CRLF & 'string in registry: ' & $regArray[$i])

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

I changed the code, and added a comment to ease the use of implementing support for more AV's

(I had accidently made an error with the array - lol)

Edit:

Fixed the error when it added every installed app to the found count :P

old code updated

Edited by FreeFry

Share this post


Link to post
Share on other sites

is there a way to exclude "My AV" from the scan?

Share this post


Link to post
Share on other sites

Dim $SupportedApps = "Trend,McAfee,Norton"  ; Add more AV's here, separate them with a comma (,)

It only finds those that are in that variable, ie. Trend, McAfee and Norton. :P

Share this post


Link to post
Share on other sites

new code only finds one AV will not look for others.

also another thought if I wanted to look for key words like antivirsus since some of these companies have other products how do I exclude "My antivirus"?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0