Check Application is Installed and Running

Please use the script to find out an application whether running and installed

import re
import _winreg
import os
from subprocess import PIPE, Popen
AppName = 'Chrome' ## Provide the Application Name here
ProName = 'chrome.exe' ## Provide the Process Name here
AppName = AppName.lower()
ProName = ProName.lower()
def DNDS(rtkey, pK, kA):
    ln = []
    lv = []
    try:
        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:
                    tls = []
                    DN, bla = _winreg.QueryValueEx(oK1, 'DisplayName')
                    DV, bla = _winreg.QueryValueEx(oK1, 'DisplayVersion')
                    _winreg.CloseKey(oK1)
                    ln.append(DN)
                    lv.append(DV)
                except:
                    pass
                i += 1
            except:
                break
        _winreg.CloseKey(oK)
        return zip(ln, lv)
    except:
        return zip(ln, lv)

rK = _winreg.HKEY_LOCAL_MACHINE
sK = r'SYSTEM\CurrentControlSet\Control\Session Manager\Environment'
openedKey = _winreg.OpenKey(rK, sK, 0, _winreg.KEY_READ)
arch, bla = _winreg.QueryValueEx(openedKey, 'PROCESSOR_ARCHITECTURE')
arch = str(arch)
_winreg.CloseKey(openedKey)

if arch == 'AMD64':
    fList = DNDS(_winreg.HKEY_LOCAL_MACHINE, r'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall', _winreg.KEY_WOW64_32KEY | _winreg.KEY_READ)
    fList.extend(DNDS(_winreg.HKEY_LOCAL_MACHINE, r'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall', _winreg.KEY_WOW64_64KEY | _winreg.KEY_READ))
    fList.extend(DNDS(_winreg.HKEY_CURRENT_USER, r'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall', _winreg.KEY_WOW64_32KEY | _winreg.KEY_READ))
    fList.extend(DNDS(_winreg.HKEY_CURRENT_USER, r'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall', _winreg.KEY_WOW64_64KEY | _winreg.KEY_READ))
else:
    fList = DNDS(_winreg.HKEY_LOCAL_MACHINE, r'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall', _winreg.KEY_READ)
    fList.extend(DNDS(_winreg.HKEY_CURRENT_USER, r'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall', _winreg.KEY_READ))
fList = set(fList)

lr = []
rs = 0
for i in fList:
    a, b = i
    if AppName in a.lower():
        lr.append('success: {} is installed'.format(a))
        lr.append('{:<25}{:5}'.format(a, b))
        rs += 1
    else:
        rs += 0

if rs > 0:
    for i in lr:
        print i
    OB = Popen('TASKLIST /FI "ImageName eq '+ProName+'" /FI "STATUS eq running"', stderr = PIPE, stdout = PIPE, shell=True)
    OUT, ERR = OB.communicate()
    RC = OB.returncode
    if RC == 0:
        if ProName in OUT:
            print '
success: {} is running'.format(ProName)
            print OUT.strip()
        else:
            print '
fail: {} is not running'.format(ProName)
    else:
        print '
fail: {} is not running'.format(ProName)
else:
    print '
fail: {} is not installed'.format(AppName)

Exported Script:

Sample Output:

Usage Instructions:
AppName = ‘Chrome’ ## Provide the Application Name here
ProName = ‘chrome.exe’ ## Provide the Process Name here

Provide the corresponding values on the above lines of code in script which you use to execute

20161223-check-application-is-installed-and-running.json (4.35 KB)

check application is installed and running.PNG

Hello @Purushothaman,

I have tried the new script that you provided, it successfully shows that sophos was installed however it fails to detect the services for the sophos. See logs below:

success: Sophos System Protection is installed Sophos System Protection 1.3.0 success: Sophos Anti-Virus is installed Sophos Anti-Virus 10.6.3.537 success: Sophos AutoUpdate is installed Sophos AutoUpdate 5.2.0.276 fail: savservice.exe is not running Thank you, Alfie

Hi @apanelo,

Please run the script as ‘Logged in User’ and Let us know the script result. Suppose the specified process is not running under System User privilege.

Thank you

Hello @Purushothaman,

Thank you the updates. However, the same logs appears. See logs below:

success: Sophos System Protection is installed Sophos System Protection 1.3.0 success: Sophos Anti-Virus is installed Sophos Anti-Virus 10.6.3.537 success: Sophos AutoUpdate is installed Sophos AutoUpdate 5.2.0.276 fail: savservice.exe is not running
Regards,
Alfie

Hi @apanelo,

As I have experimented that the Sophos application runs[started] their services instead of the application SophosUI.exe. In that case, the old script was not able to find out the running micro-apps relevant to Sophos. However, here https://forum.mspconsortium.com/forum/script-library/7455-check-application-is-installed-and-running-services we have posted a new script to get the started [running] services of the installed application.

This is very helpful to you when to find out an application whether installed and running the services in the background.

Thank you,
Purushoth

Hello @Purushothaman,

Thank you updating the script. It is now working perfectly. Appreciate your effort.

Regards,
Alfie

Hi @apanelo,

Thank you for your appreciation

Regards,
Purushoth

Hi @Purushothaman,

You are welcome.

Thank you,
Alfie