Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Windows Version Detection

by $code or die (Deacon)
on Oct 07, 2001 at 22:34 UTC ( [id://117330]=note: print w/replies, xml ) Need Help??


in reply to Windows Version Detection

use Win32; print "$_\n" for Win32::GetOSVersion();
Explanation of what is returned by Win32::GetOSVersion is of course in the docs:

Win32::GetOSVersion() CORE Returns the array (STRING, MAJOR, MINOR, BUILD, ID), where the elements are, respectively: An arbitrary descriptive string, the major version number of the operating system, the minor version number, the build number, and a digit indicating the actual operating system. For ID, the values are 0 for Win32s, 1 for Windows 9X and 2 for Windows NT. In scalar context it returns just the ID.
Simon Flack ($code or die)
$,=reverse'"ro_';s,$,\$,;s,$,lc ref sub{},e;$,
=~y'_"' ';eval"die";print $_,lc substr$@,0,3;


update: pasted doc info for Win32::GetOSVersion()
update2: Fixed miss-spell GetOSVersion() - I was doing it from memory and only later posted in from docs - should have double checked.

Replies are listed 'Best First'.
Re: Re: Windows Version Detection
by jlongino (Parson) on Oct 08, 2001 at 00:04 UTC
    For those that might try to cut/paste $code or dies' example:   print "$_\n" for Win32::GetOsVersion(); should read:   print "$_\n" for Win32::GetOSVersion(); Win32::GetOSVersion() showed up in the initial searches I made via The Perl CD Bookshelf. It was the first thing I tested but I forgot to mention it in the original post. Apologies for that.

    My primary objection to it was that I couldn't easily discern whether a system was using Windows 2000 or not. The software that I'm looking at must distinguish between win2k and nt. I'll confirm this at work Monday, since I don't have access to win2k at home. It also doesn't mention anything about Windows ME, although for my purposes it can be lumped together with win9x.

    Thanks for bringing it up though, as others will want to be aware of it as a alternative approach.

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

      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;
        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

        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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://117330]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (6)
As of 2024-04-18 19:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found