views:

452

answers:

7

How to detect OS of Win7 Home Premium, Win7 Professional, Win7 Enterprise or Win7 ultimate?

+2  A: 

Determine Windows Version and Edition

Check this post Detect OS version and see if it helps. This is for XP but it should help you little bit.

Check this one too http://andrewensley.com/2009/06/c-detect-windows-os-part-1/ and this one is for Vista.

Shoban
Thanks for the link to my blog. I hope it's helpful. +1
Andrew
A: 

Try WMI: host localhost, namespace root\cimv2 (these are the defaults) SELECT Caption FROM Win32_OperatingSystem

Piskvor
A: 

I was going to suggest looking on the box it shipped in ;)

Carl Smotricz
"dear user, please find the box your OS shipped in and type in its name"> \*sounds of head being scratched\* "Windows"
Piskvor
You just did [15chars]
Ed Swangren
+1  A: 

He tagged the question with win32 api.

GetVersionEx() et al. is what you need. See this code sample for a more in depth example.

Alex
How does this help determining the Win7 edition?
Serge - appTranslator
+1  A: 

I'm using the key "Edition" under HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion to determine windows version, I don't know if it's unique? Thanks.

EditionID = ultimate EditionID = Enterprise EditionID = Professional EditionID = Premium

Yigang Wu
A: 

Using approach like checking the version number is incorrect in my opinion. I was reading an article about best practices (lost the link) and it clearly said never use these version numbers which microsoft may change in future updates to detect windows version.

Windows Vista is version 6.0 and Windows 7 is 6.1 which ideally should have been 7. This is not a reliable at all.

A better way is to check the existance of features which are particular to each version of windows. For ex, in windows vista/7 home basic you would not find aero experience. Same way ultimate edition comes with bitlocker etc and home premium doesnt.

MSDN will detail what features are available in each version and how to query if its available. Based on this you can decide what is the base version of windows. Also you can use to query version info from the system dlls to detect exact windows build date etc.

With windows 7 new DLLs have been added in the system32 as compared to vista. So when you search for particular dlls you would know if its windows 7 system or old versions like xp/vista.

Kavitesh Singh
Windows will increment the version number, but will never decrement it. Windows 7 is labeled as version 6.1 for application compatibility reasons; there's a lot of 3rd party code out there that doesn't do a good job of checking version numbers.
Eric Brown
@ Eric Brown. Please refer this document from microsoft Windows 7 and Windows Server 2008 R2 Application Quality Cookbook available at http://code.msdn.microsoft.com/Windows7AppQuality/Release/ProjectReleases.aspx?ReleaseId=1734. Check the Operating Versioning section where in solution section it says "Generally, applications should not perform operating system version checks. If an application needs a specific feature, it is preferable to try to find the feature, and fail only if the needed feature is missing".
Kavitesh Singh
@Eric Brown: Check link(http://windowsteamblog.com/blogs/developers/archive/2009/08/05/version-checking-just-don-t-do-it.aspx) provided by Bob Moore in one of the answers posted here. "As mentioned previously, checking the operating system version is not the best way to confirm that a specific operating system feature is available. This is because the operating system may have had new features added in a redistributable DLL. Rather than using GetVersionEx to determine the operating system platform or version number, it is more effective to test for the presence of the feature itself."
Kavitesh Singh
A: 

You can use GetVersionEx to determine the core OS version, but this method gets messy faced with multiple products which use a common core, and I don't think you can programatically decode this information down to the level of a particular SKU. The best you could get away with is finding a string and letting the user see that. Some simple OSVERSIONINFOEX mappings are shown in the remarks section of the docs here

Read this Microsoft blog posting for current thinking on this topic. Basically it comes down to using GetProcAddress to look for the API you're trying to use and degrading gracefully.

Bob Moore