Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

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"

    # 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
    # so we have to handle an outside case.
    return ( $os eq "2000" & $major != 5 ) ? "NT4" : $os;
Replies are listed 'Best First'.
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.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2020-02-29 07:51 GMT
Find Nodes?
    Voting Booth?
    What numbers are you going to focus on primarily in 2020?

    Results (128 votes). Check out past polls.