Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

Lấy phiên bản ứng dụng dùng Python

Trong công nghiệp phần mềm, dev thêm tính năng, sửa bug, đặt phiên bản mới nhận diện cập nhật. Dùng Python lấy phiên bản ứng dụng. Dùng pywin32 tương tác file thực thi. Cung cấp truy cập win32 API tạo COM object.

  • Cài gói: pip install pywin32.
  • Import Dispatch lấy phiên bản.
  • Tạo biến lưu đường dẫn ứng dụng.
  • Định nghĩa hàm lấy phiên bản nhận đường dẫn file thực thi parse Dispatch.
  • Trả về phiên bản GetFileVersion(app_location).

Ví dụ

Lấy phiên bản Chrome trên hệ thống.

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

Kết quả

Chạy mã in phiên bản Chrome.

89.0.4389.114

Thử đường dẫn ứng dụng khác lấy phiên bản.