コード例 #1
0
def _createSoftware(names,
                    paths,
                    displayVersions,
                    publishers,
                    productIds,
                    installDates,
                    hostOSH,
                    OSHVResult,
                    softNameToInstSoftOSH=None):
    nameKeys = names.keys()
    for name in nameKeys:
        path = paths.get(name)
        displayVersion = displayVersions.get(name)
        publisher = publishers.get(name)
        productId = productIds.get(name)
        productCode = parseProductCode(name)
        installDate = installDates.get(name)
        softName = names.get(name)
        if softName:
            softwareOSH = hostresource.createSoftwareOSH(
                hostOSH,
                softName,
                path=path,
                displayVersion=displayVersion,
                publisher=publisher,
                productId=productId,
                productCode=productCode,
                installDate=installDate)
            OSHVResult.add(softwareOSH)
            if softNameToInstSoftOSH != None:
                softNameToInstSoftOSH[softName.strip()] = softwareOSH
        else:
            logger.debug('software: ', softName,
                         ' already reported or has no Name')
コード例 #2
0
def mainFunctionWithWbem(Framework, wmiClient, OSHVResult,
                         softNameToInstSoftOSH=None):
    '''
    Discovers installed software and, for Windows 2008, hotfixes

    This function uses Win32_Product class
    http://msdn.microsoft.com/en-us/library/windows/desktop/aa394378(v=vs.85).aspx
    It's available since Windows 2000

    In Windows 2003 Server,
    Win32_Product is not enabled by default, and must be enabled as follows:

    1.In Add or Remove Programs, click Add/Remove Windows Components.
    2. In the Windows Components Wizard, select Management and Monitoring Tools and then click Details.
    3. In the Management and Monitoring Tools dialog box, select WMI Windows Installer Provider and then click OK.
    4. Click Next.

    Cons:
    It is terribly slow (querying might take up to 10 seconds)
    It represents information only about software installed using MSI (Microsoft Installer)
    '''
    try:
        hostOSH = createHostOSH(Framework, wmiClient)
        OSHVResult.add(hostOSH)
        wmiProvider = WmiAgentProvider(wmiClient)
        softwareDiscoverer = SoftwareDiscoverer(wmiProvider)
        softwareItems = softwareDiscoverer.getInstalledSoftware()

        for software in softwareItems:
            softwareOSH = hostresource.createSoftwareOSH(
                    hostOSH, software.name, path=software.path,
                    displayVersion=software.version,
                    publisher=software.vendor,
                    productId=software.productId,
                    installDate=software.installDate)
            OSHVResult.add(softwareOSH)
            if softNameToInstSoftOSH != None:
                softNameToInstSoftOSH[software.name.strip()] = softwareOSH
        hostDiscoverer = WmiHostDiscoverer(wmiProvider)
        if hostDiscoverer.isWin2008():
            discoverWin2008HotFixes(wmiProvider, hostOSH, OSHVResult)
        if hostDiscoverer.isWindows8_2012():
            discoverWin8_2012HotFixes(wmiProvider, hostOSH, OSHVResult)

    except JavaException, ex:
        exInfo = ex.getMessage()
        pattern = "(Invalid class.?)|(Could not connect to WMI.?)"
        if (re.match(pattern, exInfo) is not None):
            logger.debug("Cannot perform regular software discovery (seems that remote 2003 Win server doesn't have appropriate WMI object installed).")
            logger.debug("Trying to discover installed software from Windows registry")
            # try to retrieve information by using old (not efficient) method using remote registry
            wmiClient.close()
            mainFunction(Framework, OSHVResult, softNameToInstSoftOSH)
            wmiClient = Framework.createClient()
        else:
            errormessages.resolveAndReport(exInfo, 'WMI', Framework)
コード例 #3
0
def discoverWin8_2012HotFixes(wmiProvider, hostOsh, OSHVResult):
    """
    Discovering win 8 or win 2012 hot fix information by executing
    @types: WmiAgentProvider, ObjectStateHolder, ObjectStateHolderVector
    @command: select HotFixID, InstallDate from Win32_QuickFixEngineering
    """
    swDiscoverer = Win8_2012SoftwareDiscoverer(wmiProvider)
    softwareItems = swDiscoverer.getInstalledHotFixes()
    for sw in softwareItems:
        softwareOSH = hostresource.createSoftwareOSH(hostOsh, sw.name,
                             installDate=sw.installDate, publisher=sw.vendor, description=sw.description)
        OSHVResult.add(softwareOSH)
コード例 #4
0
def discoverWin8_2012HotFixes(wmiProvider, hostOsh, OSHVResult):
    """
    Discovering win 8 or win 2012 hot fix information by executing
    @types: WmiAgentProvider, ObjectStateHolder, ObjectStateHolderVector
    @command: select HotFixID, InstallDate from Win32_QuickFixEngineering
    """
    swDiscoverer = Win8_2012SoftwareDiscoverer(wmiProvider)
    softwareItems = swDiscoverer.getInstalledHotFixes()
    for sw in softwareItems:
        softwareOSH = hostresource.createSoftwareOSH(
            hostOsh,
            sw.name,
            installDate=sw.installDate,
            publisher=sw.vendor,
            description=sw.description)
        OSHVResult.add(softwareOSH)
コード例 #5
0
def _createSoftware(names, paths, displayVersions, publishers, productIds,
                   installDates,
                   hostOSH, OSHVResult, softNameToInstSoftOSH=None):
    nameKeys = names.keys()
    for name in nameKeys:
        path = paths.get(name)
        displayVersion = displayVersions.get(name)
        publisher = publishers.get(name)
        productId = productIds.get(name)
        productCode = parseProductCode(name)
        installDate = installDates.get(name)
        softName = names.get(name)
        if softName:
            softwareOSH = hostresource.createSoftwareOSH(
                    hostOSH, softName, path=path,
                    displayVersion=displayVersion, publisher=publisher,
                    productId=productId, productCode=productCode,
                    installDate=installDate)
            OSHVResult.add(softwareOSH)
            if softNameToInstSoftOSH != None:
                softNameToInstSoftOSH[softName.strip()] = softwareOSH
        else:
            logger.debug('software: ', softName, ' already reported or has no Name')
コード例 #6
0
def mainFunctionWithWbem(Framework,
                         wmiClient,
                         OSHVResult,
                         softNameToInstSoftOSH=None):
    '''
    Discovers installed software and, for Windows 2008, hotfixes

    This function uses Win32_Product class
    http://msdn.microsoft.com/en-us/library/windows/desktop/aa394378(v=vs.85).aspx
    It's available since Windows 2000

    In Windows 2003 Server,
    Win32_Product is not enabled by default, and must be enabled as follows:

    1.In Add or Remove Programs, click Add/Remove Windows Components.
    2. In the Windows Components Wizard, select Management and Monitoring Tools and then click Details.
    3. In the Management and Monitoring Tools dialog box, select WMI Windows Installer Provider and then click OK.
    4. Click Next.

    Cons:
    It is terribly slow (querying might take up to 10 seconds)
    It represents information only about software installed using MSI (Microsoft Installer)
    '''
    try:
        hostOSH = createHostOSH(Framework, wmiClient)
        OSHVResult.add(hostOSH)
        wmiProvider = WmiAgentProvider(wmiClient)
        softwareDiscoverer = SoftwareDiscoverer(wmiProvider)
        softwareItems = softwareDiscoverer.getInstalledSoftware()

        for software in softwareItems:
            softwareOSH = hostresource.createSoftwareOSH(
                hostOSH,
                software.name,
                path=software.path,
                displayVersion=software.version,
                publisher=software.vendor,
                productId=software.productId,
                installDate=software.installDate)
            OSHVResult.add(softwareOSH)
            if softNameToInstSoftOSH != None:
                softNameToInstSoftOSH[software.name.strip()] = softwareOSH
        hostDiscoverer = WmiHostDiscoverer(wmiProvider)
        if hostDiscoverer.isWin2008():
            discoverWin2008HotFixes(wmiProvider, hostOSH, OSHVResult)
        if hostDiscoverer.isWindows8_2012():
            discoverWin8_2012HotFixes(wmiProvider, hostOSH, OSHVResult)

    except JavaException, ex:
        exInfo = ex.getMessage()
        pattern = "(Invalid class.?)|(Could not connect to WMI.?)"
        if (re.match(pattern, exInfo) is not None):
            logger.debug(
                "Cannot perform regular software discovery (seems that remote 2003 Win server doesn't have appropriate WMI object installed)."
            )
            logger.debug(
                "Trying to discover installed software from Windows registry")
            # try to retrieve information by using old (not efficient) method using remote registry
            wmiClient.close()
            mainFunction(Framework, OSHVResult, softNameToInstSoftOSH)
            wmiClient = Framework.createClient()
        else:
            errormessages.resolveAndReport(exInfo, 'WMI', Framework)