ในอุตสาหกรรมซอฟต์แวร์ เวอร์ชันแอปพลิเคชันช่วยระบุฟีเจอร์และการแก้ไขบั๊ก Python สามารถดึงเวอร์ชันของไฟล์ .exe ได้ด้วยไลบรารี pywin32 ซึ่งเข้าถึง Win32 API
ขั้นตอน
- ติดตั้งแพ็กเกจ:
pip install pywin32 - นำเข้า Dispatch จาก win32com.client
- กำหนดตำแหน่งไฟล์ Executable
- สร้างฟังก์ชันดึงเวอร์ชันด้วย GetFileVersion()
ตัวอย่างโค้ด
# Import the 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)
ผลลัพธ์
89.0.4389.114
ลองเปลี่ยนตำแหน่งไฟล์เพื่อดึงเวอร์ชันแอปอื่นได้