def getOutput(command): """Executes a command in the prompt and returns its result. In case of an error it returns am empty string""" try: return subprocess.check_output(command, shell=True) except Exception as err: errorHandler.logError("getOutput of %s " % str(command), err) return ""
def getDrivers(whitelist): """Gather the drivers available in this machine. Returns a list with all services, or a list with an error message if there's an error""" drvs = commandHandler.getOutput("sc query type= driver") if drvs == "": errorHandler.logError("sc calling\nThis computer can't execute sc", err) return ["Este computador não executa o comando sc. Impossível descobrir drivers."] drvs = parseSC("DRV", drvs, whitelist) return drvs
def getServices(whitelist): """Gather the services available in this machine. Returns a list with all services, or a list with an error message if there's an error""" serv = commandHandler.getOutput("sc query type= service") if serv == "": errorHandler.logError("sc calling\nThis computer can't execute sc", err) return ["Este computador não executa o comando sc. Impossível descobrir serviços."] serv = parseSC("SRV", serv, whitelist) return serv