1

Anyone know how to determine the Windows Edition ??

E.g. for both 32bit and 64bit of Windows: - Windows XP Home/Professional - Windows Vista Business/Ultimate...etc - Windows 7 Home Basic/Home Premium/Professional/Ultimate...etc

I wonder if could retrieve this info from registry or Python API ??

Thanks.

Cthoong
  • 53
  • 1
  • 9
  • See http://stackoverflow.com/questions/2816821/identify-windows-editions-with-python – Cees Timmerman Oct 27 '11 at 10:02
  • I think this "https://bitbucket.org/gastlygem/wistron/src/c16e2cfe1445/wistron.preload/wistron/preload/ostype.py" should be the solution if using pure python. As i am using python in Squish QT which may not fully support python api, so it failed to import ctypes. That's why wondering if possible to retrieve the edition from registry instead ?? – Cthoong Oct 27 '11 at 10:36

2 Answers2

1

Take a look at platform.win32_ver(). Also, see How to check if OS is Vista in Python?

Community
  • 1
  • 1
NPE
  • 486,780
  • 108
  • 951
  • 1,012
  • Actually I am using Python in Squish QT for automate testing. Did try the platform.win32.ver() but return >> (",",",") Also tried the list in this link "http://docs.python.org/library/platform.html#windows-platform" also doesn't help. – Cthoong Oct 27 '11 at 09:32
1

If ctypes doesn't work (due to 32 vs 64 bits?), this hack should:

def get_Windows_name():
    import subprocess, re
    o = subprocess.Popen('systeminfo', stdout=subprocess.PIPE).communicate()[0]
    try: o = str(o, "latin-1")  # Python 3+
    except: pass  
    return re.search("OS Name:\s*(.*)", o).group(1).strip()

print(get_Windows_name())

Or just read the registry:

try: import winreg
except: import _winreg as winreg
with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\Microsoft\Windows NT\CurrentVersion") as key:
    print(winreg.QueryValueEx(key, "EditionID")[0])

Or use this:

from win32com.client import GetObject
wim = GetObject('winmgmts:')
print([o.Caption for o in wim.ExecQuery("Select * from Win32_OperatingSystem")][0])
Cees Timmerman
  • 17,623
  • 11
  • 91
  • 124
  • I search through registry of Windows XP Pro SP3 in "Key"+"Values"+"Data", can't find the any related to "EditionID"... – Cthoong Nov 04 '11 at 04:56
  • yes, the "EditionID" is found on Vista and 7 !!! Seem like XP is different, anyone know where is the key ? – Cthoong Nov 04 '11 at 05:50
  • By search and study through internet, there's one file I found on most XP machines that indicate the edition. >> "C:\WINDOWS\system32\prodspec.ini"... This file is not available in vista and 7 as I believe the it keep in reg key (mentioned in above comment). – Cthoong Nov 04 '11 at 09:20
  • Have you tried the subprocess method? [`systeminfo`](http://www.computerhope.com/systemin.htm) is available from Windows XP Pro and up. – Cees Timmerman Nov 04 '11 at 10:05
  • As should you know that I am using Python in Squish QT, not sure is it not fully supporting Python, Squish QT tell "AttributeError: 'module' object has no attribute 'check_output'". Seems like "check_output" is not available while the "subprocess" can import. – Cthoong Nov 04 '11 at 10:18
  • for Vista and 7, i will use your method to check from reg key. for XP, i will try to extract from prodspec.ini file instead. Cees Timmerman, really appreciated on your help !!!! :) – Cthoong Nov 04 '11 at 10:22
  • It sounds like you're using a Python older than 2.7. Try searching the registry for "Windows XP Professional" or such. – Cees Timmerman Nov 04 '11 at 10:44
  • I've made the `systeminfo` method compatible with Python 2.4+. – Cees Timmerman Nov 04 '11 at 12:55
  • Can't find any key that matching "Windows XP Professional" in full. Found quite a few under "[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\SideBySide\Installations\x86_Microsoft.Windows.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\Codebases\OS" "Prompt"="Windows XP Professional Service Pack 3 CD" – Cthoong Nov 08 '11 at 02:48