http://www.perlmonks.org?node_id=144660

Use to determine the name of the windows OS that is being used. Currently handles win32s, 95, 98, Me, NT3.51, NT4, 2000,and XP/.Net. (In fact these strings are what it returns). Returns undef or () if the OS is not a Windows Box of some sort. The determination of the OS is done through the Win32 module and the API call GetOSVersion. Parsing the results is according to the specs of this function in MSDN. The snippet will try to require 'Win32' on its own if it is running on a Windows box. If it cant get Win32 it returns undef as well. Comments/Criticism, bugfixes welcome! Yves/Demerphq
sub Win_OS_Type { return unless $^O =~ /win32|dos/i; # is it a MS box? # It _should_ have Win32 unless something is really weird return unless eval('require Win32'); # Use the standard API call to determine the version my ( undef, $major, $minor, $build, $id ) = Win32::GetOSVersion; return "win32s" unless $id; # If id==0 then its a win32s + box. my $os = { # Magic numbers from MSDN do +cumentation of GetOSVersion 1 => { 0 => "95", 10 => "98", 90 => "Me" }, 2 => { 0 => "2000", 1 => "XP/.Net", 51 => "NT3.51" } }->{$id}->{$minor}; # This _really_ shouldnt happen. At least not for quite a while die "$id:$major:$minor Has no name of record!" unless defined $os; # Unfortunately the logic used for the various versions isnt so cl +ever.. # so we have to handle an outside case. return ( $os eq "2000" & $major != 5 ) ? "NT4" : $os; }