in reply to Re: Re: Windows Version Detection
in thread Windows Version Detection

Untested, but you should get the jist:
my @winver = Win32::GetOSVersion(); print "Windows 2000" if $winver[1] == 5 and $winver[4] == 2;
To find out it it's Windows Me or Windows 98 or Windows 95, you'd need somthing like this:
# I'm guessing at the major Windows versions for 9x here, but it shoul +d be easy to test: print "Windows 95" if $winver[1] == 1 and $winver[4] == 1; print "Windows 98" if $winver[1] == 2 and $winver[4] == 1; print "Windows Me" if $winver[1] == 3 and $winver[4] == 1;
Alternatively, you could build a lookup:
my $version_lookup = [ [], # Win32s (not sure what goes here) [ undef, "Windows95", "Windows98", "WindowsMe" ], [ undef, undef, undef, "NT 3", "NT 4", "Windows 2000"] ]; my @winver = Win32::GetOSVersion(); printf "Operating System is %s", $version_lookup->[$winver[4]]->[$winv +er[1]];
My point is here, that there are loads of ways of doing this, but this way is much better than using the output of "ver" You get all the imformation that "ver" gives but in a way that makes it easy to use without a regex. Plus it's easily extendible - XP is out this month, I'd be willing to bet that you could detect XP like this: (or something very similar)

print "I'm XP!!" if $winver[1] == 6 and $winver[4] == 2;
Do you know what the output of ver will be for Windows XP?

Simon Flack ($code or die)
$,=reverse'"ro_';s,$,\$,;s,$,lc ref sub{},e;$,
=~y'_"' ';eval"die";print $_,lc substr$@,0,3;

Replies are listed 'Best First'.
Re: Re: Re: Re: Windows Version Detection
by jlongino (Parson) on Oct 11, 2001 at 06:52 UTC
    This table is not complete by any means, but I thought that it might be helpful to some. Please continue to post if you should come across relevant information. I would've gone further but what I've collected so far is already above and beyond the requirements for the project at hand:
    OS $id $major $minor ----------------- --- ------ ------ MS Windows 95 1 4 0 MS Windows 98 SE 1 4 10 MS Windows ME 1 4 90 MS Windows NT 3.51 2 3 51 MS Windows NT 4.0 2 4 0 MS Windows 2000 2 5 0 MS Windows XP 2 5 1
    Where:
    use Win32; my ($string, $major, $minor, $build, $id) = Win32::GetOSVersion() +;

    "Make everything as simple as possible, but not simpler." -- Albert Einstein

Re: Re: Re: Re: Windows Version Detection
by jlongino (Parson) on Oct 08, 2001 at 03:35 UTC
    I really appreciate you going to all the trouble you have. I have already spent 3+ hours today (not counting last night) researching the various options outlined in this thread. All total I've spent at least 8 hours on the project so far and I'm still in the research stage. But since most all of that work has been on my own dime, I can probably finish up with only 8 hours at work. It has been a frustrating experience (and people think Unix is arcane?). As for using Win32::API and GetVersionEx, I haven't been able to come up with a single Perl example yet and from what I've seen so far, it's methods are far too obscure for my taste.

    I'm definitely going to use Win32::GetOSVersion(). It is just a shame that it is so difficult to find up-to-date values for the various OS versions. As for your question, I don't know about the values for XP but perhaps others reading this thread might be able to help. I'm sure I won't be needing that info for several months.

    If anyone knows of one, could you please post a link to a more complete reference for the various OS values than are in the perldocs?

    Thanks again.

    "Make everything as simple as possible, but not simpler." -- Albert Einstein