nico7nibor has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks,

I am having trouble getting the OS NT, Vista and Windows 7

This is how a portion of my code looks

($string, $major, $minor, $osbuild, $id) = Win32::GetOSVersion (); $os = ""; if ($DEBUG >= 2) { print "ID = $id\n"; } if ($id == 0) { print "Unable to determine win32s!"; } $os = { 1 => { 0 => "95", 10 => "98", 90 => "Me" }, 2 => { 0 => "2000", 1 => "XP/.Net", 2 => "Server 2003", 51 => "NT3.51" } }->{$id}->{$minor};

how can i get Oses NT 4 and Vista when they have the same minor and id with 2000, Also does the functionality supports Windows 7 OS?

second problem is i have to split the result into two. I need to compare the result to update a file to all Oses under $major <= 4, While the other split will depend on $major >=5 in which a different file is processed for the remaning Oses

Im really confused of what flow i have to implement. much thanks

Replies are listed 'Best First'.
Re: split OSVersion in two categories
by ikegami (Patriarch) on Nov 20, 2009 at 06:50 UTC

    how can i get Oses NT 4 and Vista when they have the same minor and id

    By looking at the major part of the version.

    use constant VER_PLATFORM_WIN32_WINDOWS => 1; # Win9x line use constant VER_PLATFORM_WIN32_NT => 2; # WinNT line use constant VER_NT_WORKSTATION => 1; my %oses = ( '9x 4.0 ???' => '95', '9x 4.10 ???' => '98 or 98 SE', '9x 4.90 ???' => 'Me', 'NT 3.51 ???' => 'NT3.51', 'NT 4.? ???' => 'NT4', 'NT 5.0 WS' => '2000', 'NT 5.1 WS' => 'XP', 'NT 5.2 ???' => 'XP Professional x64 Edition, ' .'Server 2003, ' .'Server 2003 R2 or ' .'Home Server', 'NT 6.0 WS' => 'Vista', 'NT 6.0 !WS' => 'Server 2008', 'NT 6.1 WS' => '7', 'NT 6.1 !WS' => 'Server 2008 R2', ); my ($id, $major, $minor, $prod_type) = ( Win32::GetOSVersion() )[4,1,2,8]; my $id_str = join(' ', $id == VER_PLATFORM_WIN32_NT ? 'NT' : '9x', "$major.$minor", $prod_type == VER_NT_WORKSTATION ? 'WS' : '!WS' ], ); my $os = $oses{$id_str};

    (Replace the "???" with the missing information.)

    See Getting the System Version. OSVERSIONINFOEX is also interesting.

      (Replace the "???" with the missing information.)

      Where can I check to replace the "???" missing information?, the code bdw works, thanks.... it seems ok even with <???>, can i leave it that way or delete, would that still be ok?

      sorry im lost about to replace the missing string

      thanks again..
        It won't work if you're on one of the systems that has "???" in its key. You could get the info by running GetOSVersion on those systems.
Re: split OSVersion in two categories
by bichonfrise74 (Vicar) on Nov 20, 2009 at 06:07 UTC
    I'm curious, what does this print for both OS?
    print $^O;