Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Which flavor of Win32?

by Mr. Muskrat (Canon)
on Jun 04, 2002 at 16:02 UTC ( [id://171531]=CUFP: print w/replies, xml ) Need Help??

After reading Master of your Environment (NT), I started looking into OS detection. The faq says to use $^O but it only returns MSWin32 which is not all that helpful. So I turned to the docs for the Win32 module. After a minute or two (or five... I wan't counting), I had some working code in place that while still somewhat lacking, works.
Updated: I have done some further breakdown of the Win32 flavors... Please correct me if I have anything wrong here... I just whipped this up.
Yet to do:
coerce $build into a valid build number...

Note: I did not use $string as it is blank under Win98 and possibly other flavors as well. The docs say this about it: "An arbitrary descriptive string".
Updated once again: I looked into the Config module as well. However, $Config{osname} returns 'MSWin32' same as $^O and $Config{osvers} returns incorrect data (at least on Win 2k).
#!/usr/bin/perl use strict; use warnings; use Win32; # this may be all some people need... print "NT\n" if (Win32::IsWinNT()); print "9x\n" if (Win32::IsWin95()); # others may want to get more indepth... my $os; my ($string, $major, $minor, $build, $id) = Win32::GetOSVersion(); $os = "Unknown Win32s flavor" if ($id == 0); if ($id == 1) { if ($minor == 90) { $os = "Win ME"; }elsif ($minor == 10) { $os = "Win 98"; }else{ $os = "Win 95"; } } if ($id == 2) { if ($major == 3) { $os = "Win NT 3.51"; }elsif ($major == 4) { $os = "Win NT 4.0"; }elsif ($major == 5) { if ($minor == 0) { $os = "Win 2k"; }elsif ($minor == 1) { $os = "Win XP"; } }else{ $os = "Unknown NT flavor"; } } print "$os, $major.$minor\n"; BEGIN { if ($^O !~ "Win32") { print "This is not a Win32 system. Exiting...\n"; exit; } }

Replies are listed 'Best First'.
(jeffa) Re: Which flavor of Win32?
by jeffa (Bishop) on Jun 04, 2002 at 17:01 UTC
    Consider a lookup table instead of nested if-else blocks:
    my %lookup = ( 1 => { 90 => 'Win ME', 10 => 'Win 98', }, 2 => { 3 => 'Win NT 3.51', 4 => 'Win NT 4.0', 5 => { 0 => 'Win 2k', 1 => 'Win XP', }, }, ); my $os = $lookup{$id}->{$minor}; $os = $os->{$major} if $minor == 5; $os ||= 'Unknown Win32s flavor'; print "$os, $major.$minor\n";
    UPDATE
    Wow - demerphq showed me Determine Windows Type or Version. Just goes to show that both Mr. Muskrat and myself should have done a little searching first. ;)

    demerphq++

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
      Good point! ++jeffa
      The original had three cases:
      Other Win32s
      Win9x
      WinNT

      While this is definately better than the original, it still requires some work.
      Update: Due to misunderstanding, I will post the original code.
      #!/usr/bin/perl use strict; use warnings; use Win32; my $os; my ($string, $major, $minor, $build, $id) = Win32::GetOSVersion(); $os = "Unknown Win32s flavor" if ($id == 0); $os = "Win9x" if ($id == 1); $os = "WinNT" if ($id == 2); print "$os, version $major.$minor\n";

      Who says that programmers can't work in the Marketing Department?
      Or is that who says that Marketing people can't program?
Re: Which flavor of Win32?
by Mr. Muskrat (Canon) on Jun 04, 2002 at 23:49 UTC
    Okay, I did some research (using google mostly) and I found that I do indeed have all the right numbers. And now that I am at home where I have Win 2k, I see that $build is now correct... Can anyone confirm that it is only correct on NT based systems?

    I have also taken jeffa's advice and used a lookup table. But, I extended what he wrote a little. Here is the latest version:
    #!/usr/bin/perl use strict; use warnings; use Win32; my ($string, $major, $minor, $build, $id) = Win32::GetOSVersion(); my %lookup = ( 1 => { 4 => { 0 => 'Win 95', 3 => 'Win 95 OSR2', # this is new! 10 => 'Win 98', 90 => 'Win ME', }, }, 2 => { 3 => { 51 => 'Win NT 3.51', }, 4 => { 0 => 'Win NT 4.0', }, 5 => { 0 => 'Win 2k', 1 => 'Win XP', }, }, ); my $os = $lookup{$id}->{$major}->{$minor}; $os ||= 'Unknown Win32s flavor'; print "$os, $major.$minor, build $build"; print ", $string" if ($string ne ""); print "\n"; BEGIN { if ($^O !~ "Win32") { print "This is not a Win32 system. Exiting...\n"; exit; } }
    Updated the code to display build number and $string...
    Who says that programmers can't work in the Marketing Department?
    Or is that who says that Marketing people can't program?
Re: Which flavor of Win32?
by demerphq (Chancellor) on Jun 24, 2002 at 10:10 UTC
    This node/code is deprecated. Upgrade to Activestate build 633.

    Then use Win32::GetOSName()

    Yves / DeMerphq
    ---
    Writing a good benchmark isnt as easy as it might look.

      Oh, darn!
      After I spent all that time! :)

      Hmm, after going through the source code for Win32.pm I see that it actually does what I was wanting to do...
      Break the Win9x flavors up by build number.
      Very nice!

      Who says that programmers can't work in the Marketing Department?
      Or is that who says that Marketing people can't program?
Re: Which flavor of Win32?
by demerphq (Chancellor) on Jun 06, 2002 at 15:48 UTC
    In confused what was wrong with Determine Windows Type or Version?

    Oh you already said that didnt you. :-) Oops. Sorry.

    Yves / DeMerphq
    ---
    Writing a good benchmark isnt as easy as it might look.

Re: Which flavor of Win32?
by Mr. Muskrat (Canon) on Jun 06, 2002 at 14:23 UTC
    Hmm, how did I miss this before? Determine Windows Type or Version fits the bill as well.

    Who says that programmers can't work in the Marketing Department?
    Or is that who says that Marketing people can't program?
Re: Which flavor of Win32?
by Mr. Muskrat (Canon) on Jun 05, 2002 at 22:47 UTC

    Windows 98 (original)
    System Properties shows it as 4.10.1998.
    However, the build number is 67766222.
    And after doing some more googles, I see that it is correct.

    Can someone guide me in the right direction as far as getting perl to know that it's 4.10.1998 (retail, OEM) vs 4.10.2222A (Second Edition)?
    Am I blind?


    Who says that programmers can't work in the Marketing Department?
    Or is that who says that Marketing people can't program?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-03-29 12:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found