[Win32utils-devel] Am I on Windows XP?
Berger, Daniel
Daniel.Berger at qwest.com
Wed Sep 24 15:43:32 EDT 2008
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
GetVersionEx(buf)
major = buf[4,4].unpack("L")[0]
minor = buf[8,4].unpack("L")[0]
suite = buf[152,2].unpack("S")[0]
# 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
then
bool = true
end
else
# Do nothing - already false
end
end
bool
end
Thanks,
Dan
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
mailing list