[Python-ideas] Determine Windows version in platform module

Andrew Barnert abarnert at yahoo.com
Sat Dec 28 20:46:56 CET 2013


On Dec 28, 2013, at 8:12, "Giampaolo Rodola'" <g.rodola at gmail.com> wrote:

> 
>> Meanwhile, Microsoft's suggested solution is that you not check for version numbers at runtime, but instead check for features. And there are good reasons for that--for example, XPSP3 N has exactly the same version numbers as XPSP3 normal, but if you try to use the new Windows Media APIs, you'll crash.
> 
> Mmm. What's weird is that if you use MSDN as a reference every Windows API has a "minimum supported client" section near the bottom of the page.
> See for example:
> http://msdn.microsoft.com/en-us/library/windows/desktop/ms684874(v=vs.85).aspx
> To me that suggests that (most of the times at least) you are encouraged to use the windows version to decide whether to support a feature or not.

Those versions don't correspond to any unique kernel version number, so you _can't_ check for it that way.

What you _can_ do with that information is write your app's version requirements, so your end users know not to buy your all if they have xpsp1.

http://msdn.microsoft.com/en-us/library/windows/desktop/ms724832(v=vs.85).aspx is one of the places they recommend against using version numbers as a substitute for feature test. it says:


way to determine whether a particular operating system feature is present. This is because the operating system may have had new features added in a redistributable DLL. Rather than using the Version API Helper functions to determine the operating system platform or version number, test for the presence of the feature itself.
To determine the best way to test for a feature, refer to the documentation for the feature of interest. The following list discusses some common techniques for feature detection:
You can test for the presence of the functions associated with a feature. To test for the presence of a function in a system DLL, call the LoadLibrary function to load the DLL. Then call the GetProcAddress function to determine whether the function of interest is present in the DLL. Use the pointer returned by GetProcAddress to call the function. Note that even if the function is present, it may be a stub that just returns an error code such as ERROR_CALL_NOT_IMPLEMENTED.
You can determine the presence of some features by using the GetSystemMetrics function. For example, you can detect multiple display monitors by callingGetSystemMetrics(SM_CMONITORS).
There are several versions of the redistributable DLLs that implement shell and common control features. For information about determining which versions are present on the system your application is running on, see the topicShell and Common Controls Versions.
If you must require a particular operating system, be sure to use it as a minimum supported version, rather than design the test for the one operating system. This way, your detection code will continue to work on future versions of Windows.
Note that a 32-bit application can detect whether it is running under WOW64 by calling the IsWow64Process function. It can obtain additional processor information by calling theGetNativeSystemInfo function.
> 
> 
> --- Giampaolo
> https://code.google.com/p/psutil/
> https://code.google.com/p/pyftpdlib/
> https://code.google.com/p/pysendfile/ 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20131228/b2dba14d/attachment.html>


More information about the Python-ideas mailing list