Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Get version of installed OS

by bimleshsharma (Beadle)
on Nov 22, 2012 at 11:18 UTC ( #1005106=perlquestion: print w/ replies, xml ) Need Help??
bimleshsharma has asked for the wisdom of the Perl Monks concerning the following question:

I have to find out version number OS(windows) that is installed on box using perl. I tried below but i could not get version number of even OS. Help is much appreciated.

use English qw' -no_match_vars '; print "$OSNAME\n";

Comment on Get version of installed OS
Download Code
Re: Get version of installed OS
by marto (Chancellor) on Nov 22, 2012 at 11:25 UTC

    Perhaps this does what you want, it uses Config which is core. Tested on Windows, Solaris and netbsd:

    #!/usr/bin/perl use strict; use warnings; use Config; print "$Config{osname}\n"; print "$Config{archname}\n"; print "$Config{osvers}\n";

    Output:

    MSWin32 MSWin32-x86-multi-thread 5.1

      Thanks.... One another way to get specially for windows is

      my $osname = Win32::GetOSName(); my ( $osvername, $major, $minor, $id ) = Win32::GetOSVersion(); print "osname: $osname\n"; print "osvername: $osvername\n"; print "major: $major\n"; print "minor: $minor\n"; print "id: $id\n";

        True, though you didn't specify which OS you were using when you posted the question ;)

        Update: I see you've just changed your question to specify OS. It'd make more sense if you'd posted that as an update to your post, like I've done here.

Re: Get version of installed OS
by GrandFather (Cardinal) on Nov 22, 2012 at 11:48 UTC

    You can use Win32 to get the information you want then a little playing around to get a OS name:

    #!/usr/bin/perl use warnings; use strict; use Win32; my %versions = ( 0 => {'' => {'' => "Win32s"}}, 1 => { 4 => { 0 => "Windows 95", 10 => "Windows 98", 90 => "Windows Me" } }, 2 => { 3 => {51 => "Windows NT 3.51"}, 4 => {0 => "Windows NT 4"}, 5 => { 0 => "Windows 2000", 1 => "Windows XP", 2 => "Windows Server 2003" }, 6 => { 0 => "Windows Vista or Server 2008", 1 => "Windows 7" } }, ); my ($name, $major, $minor, $build, $id) = Win32::GetOSVersion(); print $versions{$id}{$major}{$minor};

    Actually a little more work than that is required to do a proper job, but it is well documented in Win32::GetOSVersion() docs linked above.

    True laziness is hard work

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1005106]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (9)
As of 2014-07-25 10:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (170 votes), past polls