0

I would just like to know the answer to the title.

Preferably formatted like, {'Some program':'C:\\Program Files\\someprogram\\mainapp.exe'}

  • Depends on your definition of a "program". Not every executable is registered in windows install lists. Simply having a file that is executable means you have a program. – flakes Dec 12 '21 at 02:15
  • my definition is: all programs that have been installed with an installer, or at least all that have a start menu shortcut. – a_programmer_on_stackoverflow Dec 12 '21 at 02:47
  • 1
    See https://stackoverflow.com/questions/53132434/list-of-installed-programs/54825112 – flakes Dec 12 '21 at 03:14

1 Answers1

0

I think this does what you need...

import subprocess # import subprocess module to run external commands from Python
  
program_dict = {} # create a dict
installed_programs = subprocess.check_output(['wmic', 'product', 'get', 'name']) #run subprocess module with check_output() method
ip = str(installed_programs) #convert bytes to string
counter = 1  
try:
    for i in range(len(ip)): #iterate over every program
        while True:
            counter +=1
            program_dict[f'Program {counter}'] = ip.split("\\r\\r\\n")[6:][i]
            print(f'Programs found:\n{program_dict}')
except IndexError as error:
    print("[-] Something went wrong.\n",error)
Robin Sage
  • 969
  • 1
  • 8
  • 24