Alert if Required Software is missing on end point user

Description : This script gives you detailed information of Software Which are installed on end point.Also generates alert if the required software is uninstalled or not present

Note Please Add your software display name in code which required to get an alert if it is not presnt on end point user. You need to add your Software Display name in function i.e(“def giveinformation()”)

Please give exact display names for better output

Tested OS : This script has tested on Windows(7),Windows(8,8.1), Windows(10) Machines




import os
import sys
import _winreg
ale=0
def alert(arg):
    sys.stderr.write("%d%d%d" % (arg, arg, arg))




import re
import socket
def finding_software(name,length):
 global ale
 c=0
 d=0
 sam=os.popen('reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" /s ').read()
 sam1=os.popen('wmic product get ').read()
 reg=re.findall(name,sam)
 reg2=re.findall(name,sam1)
 #print reg
 #print reg2
 length=len(reg)
 length2=len(reg2)
 ab,bc=0,0
 if reg!=reg2 :
  if len(reg)>0:
   if len(name)==len(reg[0]):
    print reg[0]+" software is present on End point user"
    ale=ale+1
  else:
   if len(reg2)==0:
    print name+"software is not present on your End point user"
    ale=ale+1
 if len(reg2)>0:
  if len(name)==len(reg2[0]):
   d=d+1
   print reg2[0]+" software is present on End point user"
   bc=bc+1
   ale=ale+1
 else:
  if len(reg)==0:
   print name+" software is not present on your End point usert"
   ale=ale+1





def giveinformation():  
    li=["Comodo One Patch Management Agent","xxxxx"]#please give exact display name of software
    c=0
    i=0
    while c<len(li):
        c=c+1
        if li[i]!="":
            name=li[i]
            length=len(li[i])
            finding_software(name,length)
            i=i+1




def collectprograms(rtkey,pK,kA):
    import _winreg
    import os
    list=[]
    oK=_winreg.OpenKey(rtkey,pK,0,kA)
    i=0
    while True:
        try:
            bkey=_winreg.EnumKey(oK,i)
            vkey=os.path.join(pK,bkey)
            oK1=_winreg.OpenKey(rtkey,vkey,0,kA)
            try:
                DN,bla=_winreg.QueryValueEx(oK1,'DisplayName')
                DV,bla=_winreg.QueryValueEx(oK1,'DisplayVersion')
                inlist=[DN.strip(), DV.strip()]
                if inlist[1]=="None":
                    gh=0
                else:
                    print inlist[0]+" "+inlist[1]
            except:
                pass
            i+=1
        except:
            break
    _winreg.CloseKey(oK)

def programsinstalled():
    name=os.environ['username']
    print 'PC-NAME : '+name
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.connect(("8.8.8.8", 80))
    print "IP-ADDRESS : " + (s.getsockname()[0])
    print "The softwares which are installed on End point User"
    print"
"
    uninstallkey='SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall'
    if 'PROGRAMFILES(X86)' in os.environ.keys():
        rklist=[(_winreg.HKEY_LOCAL_MACHINE,uninstallkey,_winreg.KEY_WOW64_32KEY | _winreg.KEY_READ),
                (_winreg.HKEY_LOCAL_MACHINE,uninstallkey,_winreg.KEY_WOW64_64KEY | _winreg.KEY_READ),
                (_winreg.HKEY_CURRENT_USER,uninstallkey,_winreg.KEY_WOW64_32KEY | _winreg.KEY_READ),
                (_winreg.HKEY_CURRENT_USER,uninstallkey,_winreg.KEY_WOW64_64KEY | _winreg.KEY_READ)]
    else:
        rklist=[(_winreg.HKEY_LOCAL_MACHINE,uninstallkey,_winreg.KEY_READ),
                (_winreg.HKEY_CURRENT_USER,uninstallkey,_winreg.KEY_READ)]
    collected=''
    uninstalled=''
    error=''
    blacklisted=''
    hasnoss=[]
    ic=0
    uc=0
    ec=0
    for i in rklist:
        col=collectprograms(i[0], i[1], i[2])
        print col
def aler():
 if ale>0:
  alert(1)
 else :
  alert(0)

programsinstalled()
giveinformation()
aler()




Sample Output :

20170612-SW-list.json (4.9 KB)

@Saikiran

windows 10 not working

Failed 000000111

Hi @phcsolutions

Thank you for the reporting. We will fix the issue and update you.

Kannan

Hi @phcsolutions

I have updated the script and please use this script as Custom monitoring .

Please refer the below URL for how to use Custom monitoring scripts https://forum.mspconsortium.com/forum/products/other-comodo-products/comodo-device-management/wiki-faq-how-to/11486-how-to-use-custom-script-procedure-monitoring