1

I wish to disable the ability to run my program on certain Windows operating systems to prevent certain issues I can't replicate in newer versions. I would like to prevent running it on Windows XP, Vista, and eventually, 7.

How can I achieve this? For a little while I used an if statement with _platform but that did not work well or efficiently.

  • Have you checked the version of python and/or tried using `print (sys.version)`? you may need to include `import sys` depending on if that is in there already. – Matt Jul 21 '15 at 02:17
  • I have already included import sys by default due to using a variety of different commands from the module. –  Jul 21 '15 at 02:19
  • [Here](http://stackoverflow.com/questions/1093322/how-do-i-check-what-version-of-python-is-running-my-script) are some different ways that `sys.version` can be used to find info, for comparisons, etc. If you run that command on systems you do not want to use and save the output you can check and blacklist versions that are not compatible. – Matt Jul 21 '15 at 02:21
  • sys.platform will get you part of the way there. On windows7 64 bit it returns 'win32'. For more detail try platform.platform(). On my platform that returns 'Windows-7-6.1.7601-SP1'. The platform module has several other functions for even more detail that is comparable to uname options on Linux. –  Jul 21 '15 at 02:23
  • @TrisNefzger Is Windows 7-6.1.7601 the final build of Windows 7 or just the current update it is on? –  Jul 21 '15 at 02:29
  • It is just the version that I have and works fine. I do not know if it is the final build. –  Jul 21 '15 at 02:34
  • Okay, thank you. I looked into the platform.platform() function and found I can put the argument (correct me if I am wrong with that term) terse = 1 in there and it will simplify it to Windows-7 or Windows-8. –  Jul 21 '15 at 02:38

1 Answers1

1

You can use sys.getwindowsversion:

import sys

ver = sys.getwindowsversion()
if ver.major == 6 and ver.minor == 1:
    print('Windows 7')
elif ver.major == 6 and ver.minor == 0:
    print('Windows Vista')
elif ver.major == 5 and ver.minor == 0:
    print('Windows XP')

Version numbers taken from this page.

101
  • 8,514
  • 6
  • 43
  • 69