Tuesday, November 19, 2024
Google search engine
HomeLanguagesGet Application Version using Python

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: This method is used for retrieving the version information for a given file
GetFileVersionInfo(File Path, SubBlock, **attr)
  • LOWORD: An interface to the win32api LOWORD macro. Value is of integer datatype
LOWORD(val)
  • HIWORD: An interface to the win32api HIWORD macro. Value is of integer datatype
HIWORD(val)

Approach:

  • First we will parse file information using GetFileVersionInfo() method.
  • File information is in the form of a dictionary, we will fetch two information, one is msfileversion and another one is lsfileversion

Below is the implementation:

Python3




# 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:

  • We will create an information parser that will parse the required information using Dispatch() method.
  • Then we will fetch the file version using the GetFileVersion() method.

Below is the implementation:

Python3




# 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

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments