Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Determine Windows Type or Version

by demerphq (Chancellor)
on Feb 11, 2002 at 17:56 UTC ( #144660=snippet: print w/ replies, xml ) Need Help??

Description: 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;
}
Comment on Determine Windows Type or Version
Download Code
Re: Determine Windows Type or Version
by demerphq (Chancellor) on Jun 24, 2002 at 10:08 UTC
    This node/code is deprecated.

    Please install ActiveState Build 633, it comes with a function called Win32::GetOSName()

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

Back to Snippets Section

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (12)
As of 2014-10-23 17:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (126 votes), past polls