detecting Win95/Win98/WinME

J

Joel VanderWerf

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?
 
P

Park Heesob

Hi,
----- Original Message -----
From: "Joel VanderWerf" <[email protected]>
To: "ruby-talk ML" <[email protected]>
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
 
P

Phil Tomson

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
 
J

Joel VanderWerf

Phil said:
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?[/QUOTE]

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:

http://www.computerhope.com/verhlp.htm

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 :(
 
N

nobu.nokada

Hi,

At Tue, 20 Jan 2004 14:01:12 +0900,
Joel said:
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.
 
D

Daniel Berger

Joel VanderWerf said:
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
 
P

Phil Tomson

Joel VanderWerf said:
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
 
J

Joel VanderWerf

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?)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top