Detecting Win95/Win98/WinME

Some of the File#flock arguments do not work on Win95/Win98/WinME
(namely LOCK_SH and LOCK_NB), so I’m looking for a way to detect what
kind of windows the process is running on. RUBY_PLATFORM and rbconfig.rb
do not seem to help.

Any ideas?

Hi,

···

----- Original Message -----
From: “Joel VanderWerf” vjoel@PATH.Berkeley.EDU
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Tuesday, January 20, 2004 8:29 AM
Subject: detecting Win95/Win98/WinME

Some of the File#flock arguments do not work on Win95/Win98/WinME
(namely LOCK_SH and LOCK_NB), so I’m looking for a way to detect what
kind of windows the process is running on. RUBY_PLATFORM and rbconfig.rb
do not seem to help.

Any ideas?

How about ver ?

C:>irb
irb(main):001:0> ver
=> “\nMicrosoft Windows 2000 [Version 5.00.2195]\n”

Regards,
Park Heesob

Joel VanderWerf vjoel@PATH.Berkeley.EDU wrote in message news:400C6835.1010203@path.berkeley.edu

Some of the File#flock arguments do not work on Win95/Win98/WinME
(namely LOCK_SH and LOCK_NB), so I’m looking for a way to detect what
kind of windows the process is running on. RUBY_PLATFORM and rbconfig.rb
do not seem to help.

Any ideas?

This is stolen from Moonwolf’s “init.rb” file (part of the win32/winbase module).

require “Win32API”

buf = [148].pack(“L”)+“\0”*144
b = Win32API.new(‘kernel32’,‘GetVersionExA’,‘P’,‘I’).call(buf)
if b != 0
(size,major,minor,build,platform,version)=buf.unpack(“LLLLLA128”)
WINVER = (major << 8) | minor
WINVER_MAJOR = major
WINVER_MINOR = minor
WINVER_BUILD = build
WIN32_WINDOWS = WINVER
case platform
when 0 #Win32s
WINVER_OSNAME = “Win32s”
WINPLATFORM = “Win32s”
UNICODE = false
WIN32_IE = 0x000
when 1 #Win95/98
WINPLATFORM = “Win95”
UNICODE = false
if minor==0 #Win95
if build >= 1212 #Win95OSR2.5
WINVER_OSNAME = “Win95OSR2.5”
WIN32_IE = 0x300
elsif build >= 1111 #Win95OSR2
WINVER_OSNAME = “Win95OSR2”
WIN32_IE = 0x300
else #Win95
WINVER_OSNAME = “Win95”
WIN32_IE = 0x200
end
else #Win98/98SE/Me
case minor
when 0x10 #98/98SE
if build>=2222 #98SE
WINVER_OSNAME = “Win98SE”
WIN32_IE = 0x400
else #98
WINVER_OSNAME = “Win98”
WIN32_IE = 0x400
end
when 0x90 #Me
WINVER_OSNAME = “WinMe”
WIN32_IE = 0x500
else
WINVER_OSNAME = “Win98???”
WIN32_IE = 0x400
end
end
when 2 #WinNT/2000
WINPLATFORM = “WinNT”
if major==4 #WinNT4
WINVER_OSNAME = “WinNT4”
UNICODE = true
WIN32_IE = 0x300
elsif major==5 #Win2000
WINVER_OSNAME = “Win2000”
UNICODE = true
WIN32_IE = 0x400
else #WinNT3.5
WINVER_OSNAME = “WinNT3.x???”
UNICODE = true
WIN32_IE = 0x000
end
end
else
WINVER_OSNAME = “???”
UNICODE = false
WINVER = 0x400
WIN32_WINDOWS = 0x400
WIN32_IE = 0x300
end

puts WINVER_OSNAME

Regards,

Dan

irb(main):001:0> ver
=> “\nMicrosoft Windows 2000 [Version 5.00.2195]\n”

Thanks, that does the trick.

djberg96@hotmail.com (Daniel Berger) wrote in message news:6e613a32.0401200913.266461a8@posting.google.com

Joel VanderWerf vjoel@PATH.Berkeley.EDU wrote in message news:400C6835.1010203@path.berkeley.edu

Some of the File#flock arguments do not work on Win95/Win98/WinME
(namely LOCK_SH and LOCK_NB), so I’m looking for a way to detect what
kind of windows the process is running on. RUBY_PLATFORM and rbconfig.rb
do not seem to help.

Any ideas?

This is stolen from Moonwolf’s “init.rb” file (part of the win32/winbase module).

require “Win32API”

buf = [148].pack(“L”)+“\0”*144
b = Win32API.new(‘kernel32’,‘GetVersionExA’,‘P’,‘I’).call(buf)
if b != 0
(size,major,minor,build,platform,version)=buf.unpack(“LLLLLA128”)
WINVER = (major << 8) | minor
WINVER_MAJOR = major
WINVER_MINOR = minor
WINVER_BUILD = build
WIN32_WINDOWS = WINVER
case platform
when 0 #Win32s
WINVER_OSNAME = “Win32s”
WINPLATFORM = “Win32s”
UNICODE = false
WIN32_IE = 0x000
when 1 #Win95/98
WINPLATFORM = “Win95”
UNICODE = false
if minor==0 #Win95
if build >= 1212 #Win95OSR2.5
WINVER_OSNAME = “Win95OSR2.5”
WIN32_IE = 0x300
elsif build >= 1111 #Win95OSR2
WINVER_OSNAME = “Win95OSR2”
WIN32_IE = 0x300
else #Win95
WINVER_OSNAME = “Win95”
WIN32_IE = 0x200
end
else #Win98/98SE/Me
case minor
when 0x10 #98/98SE
if build>=2222 #98SE
WINVER_OSNAME = “Win98SE”
WIN32_IE = 0x400
else #98
WINVER_OSNAME = “Win98”
WIN32_IE = 0x400
end
when 0x90 #Me
WINVER_OSNAME = “WinMe”
WIN32_IE = 0x500
else
WINVER_OSNAME = “Win98???”
WIN32_IE = 0x400
end
end
when 2 #WinNT/2000
WINPLATFORM = “WinNT”
if major==4 #WinNT4
WINVER_OSNAME = “WinNT4”
UNICODE = true
WIN32_IE = 0x300
elsif major==5 #Win2000
WINVER_OSNAME = “Win2000”
UNICODE = true
WIN32_IE = 0x400
else #WinNT3.5
WINVER_OSNAME = “WinNT3.x???”
UNICODE = true
WIN32_IE = 0x000
end
end
else
WINVER_OSNAME = “???”
UNICODE = false
WINVER = 0x400
WIN32_WINDOWS = 0x400
WIN32_IE = 0x300
end

puts WINVER_OSNAME

What about XP? I suspect it falls somewhere in the WinNT/2000 case.

Phil

Daniel Berger wrote:

This is stolen from Moonwolf’s “init.rb” file (part of the win32/winbase module).

Thanks. I’ll keep that in mind in case the ver solution doesn’t work
out. (Or is there a strong case for using the Win32API GetVersionExA
call anyway?)

In article 400C7EF0.2080606@path.berkeley.edu,

···

Joel VanderWerf vjoel@PATH.Berkeley.EDU wrote:

irb(main):001:0> ver
=> “\nMicrosoft Windows 2000 [Version 5.00.2195]\n”

Thanks, that does the trick.

Hmmm… but that’s not exactly cross-platform.
Is ver available on all flavors of Windows?

BTW: you could probably check some section of the Registry, but it’s not
very straightforward in my experience.

Phil

Hi,

···

At Wed, 21 Jan 2004 10:20:00 +0900, Phil Tomson wrote:

What about XP? I suspect it falls somewhere in the WinNT/2000 case.

It is NT 5.1, isn’t it?


Nobu Nakada

Phil Tomson wrote:

What about XP? I suspect it falls somewhere in the WinNT/2000 case.

AFAIK, XP is NT 5.1 (major == 5, minor == 1).

emmanuel

Phil Tomson wrote:

In article 400C7EF0.2080606@path.berkeley.edu,

irb(main):001:0> ver
=> “\nMicrosoft Windows 2000 [Version 5.00.2195]\n”

Thanks, that does the trick.

Hmmm… but that’s not exactly cross-platform.
Is ver available on all flavors of Windows?

I’ve tried it on ME, and Park Heesob tried it on Win2K, so now we know
it works on two.

Actually, this page suggests that it is standard:

But this page is wrong about the output on ME. It says ‘Windows ME
4.90.3000’, but I got something like ‘Windows Millenium …’. So I’m
assuming it could be either.

BTW: you could probably check some section of the Registry, but it’s not
very straightforward in my experience.

I quail at the thought :frowning:

···

Joel VanderWerf vjoel@PATH.Berkeley.EDU wrote:

Hi,

···

At Tue, 20 Jan 2004 14:01:12 +0900, Joel VanderWerf wrote:

irb(main):001:0> ver
=> “\nMicrosoft Windows 2000 [Version 5.00.2195]\n”

Thanks, that does the trick.

Hmmm… but that’s not exactly cross-platform.
Is ver available on all flavors of Windows?

I’ve tried it on ME, and Park Heesob tried it on Win2K, so now we know
it works on two.

ver command has been available from DOS, 2.x at least AFAIK.

However, it tells about the command interpreter but not about
the system. It can be changed by COMSPEC.


Nobu Nakada