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

Greetings PerlMonks,

$^O will give the OS Name (ie: MSWin32) but how do I determine if it's Windows 2003 or 2008?
I'd like to use something easy like:
#!C:/Perl/bin/perl.exe -w use Config; use strict; print "\nOS name: ".$Config{'osname'}; print "\nOS archname: ".$Config{'archname'}; print "\nOS version: ".$Config{'osvers'};
but I can't seem to find anything that identifies the system I'm using as a Windows 2008 OS without going to extraordinary lengths like:
#!C:/Perl/bin/perl.exe -w use Win32::OLE qw(in with); $host = "127.0.0.1"; $WMI = Win32::OLE->new('WbemScripting.SWbemLocator') || die "Cannot access WMI on local machine: ", Win32::OLE->LastError; $Services = $WMI->ConnectServer($host) || die "Cannot access WMI on remote machine: ", Win32::OLE->LastError; $os_set = $Services->InstancesOf("Win32_OperatingSystem"); foreach $os (in($os_set)) { $os_name = $os->{'Caption'}; } print "$os_name\n";
... which gives me "Microsoft<< Windows Server<< 2008 Enterprise

Is there an easier way?

Replies are listed 'Best First'.
Re: Finding OS Version and Win2K8
by BrowserUk (Patriarch) on May 23, 2008 at 04:31 UTC
      I think Win32::GetOSName() does not support 2008 yet and you need to keep Win32 recent for that since Win32::GetOSName() also (like Sys::Info) uses hard coded names and checks the OS version. The manual way is to check Major & Minor from Win32::GetOSVersion()
        FYI...

        Both Win32::GetOSName and Sys::Info return "WinVista", not "Win2008".

        The only way I've been able to determine if the system I'm on is Windows 2008 is by running that really long script using Win32::OLE in the example at the top of the thread.

        I guess I'll just stick with that one for the time being. Thank you to all who replied!!! Mark
Re: Finding OS Version
by Khen1950fx (Canon) on May 22, 2008 at 22:05 UTC
      Thank you for the response Khen1950fx, however...

      when I run the POSIX::uname()script (in the link you provided) on my Win2K8 Enterprise Server, it returns "Windows NT" and "6.0"

      I'm looking for a simple command that actually dislays "Windows 2008" - preferably more simple than the one I posted in my second example.

      Just to clarify my reasons... Windows 2K8 Enterprise Server handles logical drives differently than Windows 2K3, even though they are both MSWin32 systems. I have to be able to differentiate between the two.
        I'm sorry that it didn't work right. I'm looking back at some of my other scripts. If I can find anything, I'll get back to you with it.

        update: This worked for me on XP:

        #!/usr/bin/perl use strict; use warnings; use Sys::Info; my $info = Sys::Info->new; my $os = $info->os; printf "Operating System is %s\n", $os->long_name;