[Win32utils-devel] Am I on Windows XP?
Daniel.Berger at qwest.com
Wed Sep 24 18:52:34 EDT 2008
> -----Original Message-----
> From: win32utils-devel-bounces at rubyforge.org
> [mailto:win32utils-devel-bounces at rubyforge.org] On Behalf Of
> Berger, Daniel
> Sent: Wednesday, September 24, 2008 1:44 PM
> To: Development and ideas for win32utils projects
> Subject: [Win32utils-devel] Am I on Windows XP?
> Hi all,
> I was looking over a code snippet to determine if I was on
> Windows XP or not. Normally this would be easy - just check
> for major version 5, minor version 1.
> There's one snag, though. According to the MSDN docs, a 64
> bit Windows XP Pro will return a minor version of 2. So, how
> do we distinguish between Windows Server 2003 and a 64 bit Windows XP?
> This is what I came up with. It feels pretty hackish, as I'm
> just checking the suitemask to see if any 2003 features are
> installed, but maybe it works. Is there a more elegant solution?
> def windows_xp?
> bool = false
> buf = 0.chr * 156
> buf[0,4] = [buf.size].pack("L") # Set the size
> major = buf[4,4].unpack("L")
> minor = buf[8,4].unpack("L")
> suite = buf[152,2].unpack("S")
> # Make sure we detect a 64-bit Windows XP Pro
> if major == 5
> if minor == 1
> bool = true
> elsif minor == 2
> if suite && VER_SUITE_BLADE == 0 &&
> suite && VER_SUITE_COMPUTE_SERVER == 0 &&
> suite && VER_SUITE_DATACENTER == 0 &&
> suite && VER_SUITE_ENTERPRISE == 0 &&
> suite && VER_SUITE_STORAGE_SERVER == 0
> bool = true
> # Do nothing - already false
Whoops, should be single '&' there, e.g. "suite & VER_SUITE_BLADE". I
could probably use some parens, too. But you get the idea. :)
This communication is the property of Qwest and may contain confidential or
privileged information. Unauthorized use of this communication is strictly
prohibited and may be unlawful. If you have received this communication
in error, please immediately notify the sender by reply e-mail and destroy
all copies of the communication and any attachments.
More information about the win32utils-devel