Kaseya Community

Check to see if a program is installed.

  • Hey,

    I want to uninstall Malwarebytes on the client computers and using Agent Procedures I am able to uninstall the program.  The issue is that malwarebytes is not installed on every computer.  what I would like to do is put something in my Agent Procedure to check to see if Malwarebytes is installed on the machine, if it is proceed to the next step to uninstall the program.  If it is not installed end the procedure.

    If you have not guessed, I am very new to writing scripts and could use some help.  If anyone has any insight on how I can do that I would appreciate it.

    Thanks.

  • I would think that the easiest way would be to see if a registry entry existed for malwarebytes. Use the IF statement in your script to check for a registry value related to malwarebytes, if it exists then skip....if not, then install malwarebytes. Or if you have the Kaseya AntiMalware module....you can uninstall and install from there. Hope this helps.

  • Mine's a little something like this:

    IF File Path "C:\Program Files\Malwarebytes' Anti-Malware\unins000.exe" Exists,

    Execute "C:\Program Files\Malwarebytes' Anti-Malware\unins000.exe" /VERYSILENT as the system account, yadda yadda.

     

    I include a second check & run pass for unins001.exe in case of second-gen (removed and reinstalled) installation.

  • Here's a vbscript I use, if it's helpful, it's pretty global and can be used for a lot of searches. it'll dump a log file called app_echo.log

     

    'Created By danrche

    'run with command line arguments 

    'to get app string match 

    'and version match or less then

    'example :

    'app_ver_check.vbs "adobe reader" 1001

    'that should check for adobe reader

    'versions are upto date for 10

     

     

    Set oArgs = WScript.Arguments

    iCount = WScript.Arguments.Count

    sCmdLine0 = WScript.Arguments.Item(0)

    iCmdLine1 = WScript.Arguments.Item(1)

    If iCount <> 2 Then

    WScript.Echo "The correct usage is 'App_Ver_Check.vbs 'app' 'version''"

    ElseIf IsNumeric(iCmdLine1) <> True Then

    WScript.Echo "The version number should be of a numerical value with no '' or ."

    Else

    sfindapp sCmdLine0, iCmdLine1

    End IF

     

    Sub sfindapp(sAPP, iVersion)

    On Error Resume Next

    iFound = 0 'place holder if not found

    Const HKEY_LOCAL_MACHINE = &H80000002

    Set WshShell = WScript.CreateObject("WScript.Shell")

    Set WshNetwork = WScript.CreateObject("Wscript.Network")

    Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & WshNetwork.ComputerName & "\root\default:StdRegProv")

    strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"

    oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys

    For Each subkey In arrSubKeys

    disHolder = WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" _

    & subkey & "\DisplayName")

    disVer =  WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" _

    & subkey & "\DisplayVersion")

    If instr(1, disHolder, sAPP, 1) = 1 Then

    iFound = 1

    myArray = split(disVer, ".")

    t = ""

    For Each x In myArray

    t = t & x

    Next

    If CLng(t) >= CLng(iVersion) Then

    'Wscript.Echo CLng(t) & " " & CLng(iVersion) & " " & disVer

    logfile(disHolder + " :  " + disVer)

    ElseIf CLng(t) < CLng(iVersion) Then

    'Wscript.Echo CLng(t) & " " & CLng(iVersion) & " " & disVer & " 2nd"

    miMsg = disHolder & " Version Deficiency " & disVer

    logfile(miMsg)

    End If

    End If

    Next

    If iFound = 0 Then logfile(sAPP + " not found")

    End Sub

     

    Function logfile(text)

    Const ForReading = 1, ForWriting = 2, ForAppending = 8

    Dim fso, f

    Set fso = CreateObject("Scripting.FileSystemObject")

    set f = fso.OpenTextFile("C:\support\app_echo.log", ForWriting, True)

    f.WriteLine text

    f.close

    End Function

  • if you change it up a bit, you can get it to auto uninstall as well. 

     

    'Created By danrche

    'run with command line arguments 

    'to get app string match 

    'and version match or less then

    'example :

    'app_ver_check.vbs "adobe reader" 1001

    'that should check for adobe reader

    'versions are upto date for 10

     

     

    Set oArgs = WScript.Arguments

    iCount = WScript.Arguments.Count

    sCmdLine0 = WScript.Arguments.Item(0)

    iCmdLine1 = WScript.Arguments.Item(1)

    If iCount <> 2 Then

    WScript.Echo "The correct usage is 'App_Ver_Check.vbs 'app' 'version''"

    ElseIf IsNumeric(iCmdLine1) <> True Then

    WScript.Echo "The version number should be of a numerical value with no '' or ."

    Else

    sfindapp sCmdLine0, iCmdLine1

    End IF

     

    Sub sfindapp(sAPP, iVersion)

    On Error Resume Next

    iFound = 0 'place holder if not found

    Const HKEY_LOCAL_MACHINE = &H80000002

    Set WshShell = WScript.CreateObject("WScript.Shell")

    Set WshNetwork = WScript.CreateObject("Wscript.Network")

    Set oReg = GetObject("winmgmts:\\" & WshNetwork.ComputerName & "\root\default:StdRegProv")

    strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"

    oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys

    For Each subkey In arrSubKeys

    disHolder = WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" _

    & subkey & "\DisplayName")

    unistString =  WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" _

    & subkey & "\UninstallString")

    If instr(1, disHolder, sAPP, 1) = 1 Then

    iFound = 1

    'Wscript.Echo unistString

    If instr(1, unistString, "msiexec", 1) = 1 Then 

    WshShell.Run "msiexec.exe /x" & subkey & " /qn /norestart", True

    Else

    WshShell.Run unistString

    End If

    End If

    Next

    If iFound = 0 Then logfile(sAPP + " not found")

    End Sub

     

    Function logfile(text)

    Const ForReading = 1, ForWriting = 2, ForAppending = 8

    Dim fso, f

    Set fso = CreateObject("Scripting.FileSystemObject")

    set f = fso.OpenTextFile("C:\support\app_unist.log", ForWriting, True)

    f.WriteLine text

    f.close

    End Function

  • Ask yourself...  Why do you want to know a program exists before you uninstall it?

    If it doesn't exist and you run the uninstall anyway, will this cause problems??

    I can suggest if you have to download an uninstall program before you do the uninstall, then you should do the check.

    If the uninstall program is already on the local machine or network, just run it.

    I have not come across an install and uninstall apps do not take care of existance of previous versions.

    My point is,  Don't make your agent procedures too complicated.  You will have to support them over the long run.