Python 检查 Windows 服务器版本 [英] Python check windows server version

查看:52
本文介绍了Python 检查 Windows 服务器版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了报告目的,我需要在我的 python 应用程序中记录当前的 Windows 版本,但我迄今为止发现的内置函数无法区分 Windows 客户端和服务器版本之间的区别:

I need to log the current windows version in my python application for reporting purposes, but the built in functions I've found so far cant tell the difference between Windows client and server versions:

os.sys.getwindowsversion()
(6, 0, 6002, 2, 'Service Pack 2')
platform.release()
'Vista'
platform.win32_ver()
('Vista', '6.0.6002', 'SP2', 'Multiprocessor Free')

这些函数在 Windows Vista 和 Windows Server 2008 上返回相同的值(因为它们共享相同的版本号).

These functions return the same values on Windows Vista and Windows Server 2008 (Since they share the same version number).

有没有办法获得正确的 Windows 版本?

Is there any way to get the correct windows version?

推荐答案

您可以使用 GetVersionEx Win32 API 并检查 wProductType 的值以进行区分.

You could use the GetVersionEx Win32 API and check the value of wProductType to differentiate.

查看 Python for Windows 扩展 包.

VER_NT_DOMAIN_CONTROLLER 0x0000002

VER_NT_DOMAIN_CONTROLLER 0x0000002

系统是一个域控制器并且操作系统是 Windows Server2008、Windows Server 2003 或 Windows2000 服务器.

The system is a domain controller and the operating system is Windows Server 2008, Windows Server 2003, or Windows 2000 Server.

VER_NT_SERVER 0x0000003

VER_NT_SERVER 0x0000003

操作系统是Windows Server2008、Windows Server 2003 或 Windows2000 服务器.

The operating system is Windows Server 2008, Windows Server 2003, or Windows 2000 Server.

请注意,服务器也是域控制器报告为VER_NT_DOMAIN_CONTROLLER,不是VER_NT_SERVER.

Note that a server that is also a domain controller is reported as VER_NT_DOMAIN_CONTROLLER, not VER_NT_SERVER.

VER_NT_WORKSTATION 0x0000001

VER_NT_WORKSTATION 0x0000001

操作系统是Windows Vista,Windows XP 专业版、Windows XP家庭版,或 Windows 2000专业.

The operating system is Windows Vista, Windows XP Professional, Windows XP Home Edition, or Windows 2000 Professional.

这篇关于Python 检查 Windows 服务器版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆