Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Windows Version in Python

when i type into the Console(CMD) "winver" i will get my windows version (The four numbers left of the build number, example: 1803,1903,1909,2004,20H2) But how can i get my windows version in python? i already tried:

import os
os.system("winver")
input()

But then it will open a new window like in the cmd, but i just want to print the winver without the rest, therefore i did this:

import os
os.system("Reg Query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v ReleaseId")
input()

But here is the problem that a string is in a string. "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion"

How can i fix that? Please help!

like image 265
Temal Avatar asked Jan 25 '26 22:01

Temal


1 Answers

you can use platform module

import platform

print(platform.platform())
print(platform.system())
print(platform.release())
print(platform.version())
print(platform.version().split('.')[2]) 
print(platform.machine())

output:

Windows-10-10.0.19041-SP0
Windows
10
10.0.19041
19041
AMD64
like image 65
just a stranger Avatar answered Jan 28 '26 12:01

just a stranger



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!