Open In App

Get Application Version using Python

Software versioning maybe thanks to reasoning the distinctive states of pc software package because it is developed and discharged. The version symbol is typically a word, a number, or both. For instance, version 1.0 is often accustomed to denote the initial unharness of a program. In this article, we will see how to get an application version number using Python.

Method 1: Here will use the win32api module.



Python extensions for Microsoft Windows Provide access to a lot of the Win32 API, the flexibility to make and use COM objects, and therefore the Pythonwin atmosphere.

Before getting started, we need to install the Module



pip install pywin32

Here we will use these methods:

GetFileVersionInfo(File Path, SubBlock, **attr)
LOWORD(val)
HIWORD(val)

Approach:

Below is the implementation:




# Import Module
from win32api import *
  
def get_version_number(file_path):
  
    File_information = GetFileVersionInfo(file_path, "\\")
  
    ms_file_version = File_information['FileVersionMS']
    ls_file_version = File_information['FileVersionLS']
  
    return [str(HIWORD(ms_file_version)), str(LOWORD(ms_file_version)),
            str(HIWORD(ls_file_version)), str(LOWORD(ls_file_version))]
  
file_path = r'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe'
  
version = ".".join(get_version_number(file_path))
  
print(version)

Output:

88.0.4324.104

Method 2: Using win32com

Here will use the win32com module. Before getting started we need to install the Module

pip install pypiwin32

Approach:

Below is the implementation:




# Import Module
from win32com.client import *
  
def get_version_number(file_path):
  
    information_parser = Dispatch("Scripting.FileSystemObject")
    version = information_parser.GetFileVersion(file_path)
    return version
  
file_path = r'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe'
version = get_version_number(file_path)
  
print(version)

Output:

88.0.4324.104

Article Tags :