Jump to content

multiple variable


Recommended Posts

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
Link to comment
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.

Link to comment
Share on other sites

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
Link to comment
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

Link to comment
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)

Link to comment
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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
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])
Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...