Last active
May 5, 2023 16:30
-
-
Save redtrillix/1354e57df5b84d3c31cb84b037afe20f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data/** |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
import os | |
import tkinter as tk | |
from tkinter import filedialog | |
from datetime import datetime | |
import win32api | |
import msilib | |
# Create a GUI window to select files | |
root = tk.Tk() | |
root.withdraw() | |
files = filedialog.askopenfilenames( | |
title="Select Programs", | |
filetypes=[("Executable files", "*.exe"), ("MSI files", "*.msi")] | |
) | |
# Create a directory for the output file, if it doesn't already exist | |
output_dir = "data" | |
if not os.path.exists(output_dir): | |
os.mkdir(output_dir) | |
# Create a CSV file and write header row | |
output_file = os.path.join(output_dir, "program_versions.csv") | |
with open(output_file, "w", newline="") as csv_file: | |
writer = csv.writer(csv_file) | |
writer.writerow(["Program Name", "EXE Version", "MSI Version", "DateTime"]) | |
# Iterate through selected files and get version numbers | |
for file_path in files: | |
program_name = file_path.split("/")[-1] # Get file name from path | |
if file_path.endswith('.msi'): | |
msi_db = msilib.OpenDatabase(file_path, msilib.MSIDBOPEN_READONLY) | |
view = msi_db.OpenView("SELECT `Value` FROM `Property` WHERE `Property`='ProductVersion'") | |
view.Execute(None) | |
record = view.Fetch() | |
msi_version = record.GetString(1) | |
view.Close() | |
else: | |
msi_version = "N/A" | |
exe_version = win32api.GetFileVersionInfo(file_path, "\\")['FileVersionLS'] | |
now = datetime.now().strftime("%Y/%m/%d %H:%M:%S") | |
# Write program and version info to CSV file | |
writer.writerow([program_name, exe_version, msi_version, now]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment