http://qs321.pair.com?node_id=238398

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

Does anybody know what is the ID column in the following table and where it comes from? The table is taken from perlport manpage:
OS $^O $Config{archname} ID Version -------------------------------------------------------- MS-DOS dos ? PC-DOS dos ? OS/2 os2 ? Windows 3.1 ? ? 0 3 01 Windows 95 MSWin32 MSWin32-x86 1 4 00 Windows 98 MSWin32 MSWin32-x86 1 4 10 Windows ME MSWin32 MSWin32-x86 1 ? Windows NT MSWin32 MSWin32-x86 2 4 xx Windows NT MSWin32 MSWin32-ALPHA 2 4 xx Windows NT MSWin32 MSWin32-ppc 2 4 xx Windows 2000 MSWin32 MSWin32-x86 2 5 xx Windows XP MSWin32 MSWin32-x86 2 ? Windows CE MSWin32 ? 3 Cygwin cygwin ?
I found no clue in either the Config manpage or perlport one. I know i should rely on other modules to know the exact OS under Windows, but i'd like to use that ID column if possible.


$|=$_="1g2i1u1l2i4e2n0k",map{print"\7",chop;select$,,$,,$,,$_/7}m{..}g

Replies are listed 'Best First'.
Re: perlport, MSWin32 and ID column
by Courage (Parson) on Feb 25, 2003 at 13:21 UTC
    That piece of doc expains dosish platforms, so it is closely related to Win32::GetOSVersion function.
    perldoc Win32 contains an answer to your question:
    Win32::GetOSVersion() [CORE] Returns the array (STRING, MAJOR, MINOR, BUILD, ID), where the elements are, respectively: An arbitrary descriptive string, t +he major version number of the operating system, the minor version number, the build number, and a digit indicating the actual operating system. For the ID, the values are 0 for Win32s, 1 for Windows 9X and 2 for Windows NT/2000/XP. In scalar context it returns just the ID. Currently known values for ID MAJOR and MINOR are as follows: OS ID MAJOR MINOR Win32s 0 - - Windows 95 1 4 0 Windows 98 1 4 10 Windows Me 1 4 90 Windows NT 3.51 2 3 51 Windows NT 4 2 4 0 Windows 2000 2 5 0 Windows XP 2 5 1 Windows .NET Server 2 5 1 Unfortunately as of June 2002 there is no way to distinguish betwe +en .NET servers and XP servers without using additional modules.

    Courage, the Cowardly Dog

      Thanks, that's exactly what i needed to know.
      Win32::GetOSVersion() in scalar context will get the job done :)


      $|=$_="1g2i1u1l2i4e2n0k",map{print"\7",chop;select$,,$,,$,,$_/7}m{..}g

Re: perlport, MSWin32 and ID column
by bart (Canon) on Feb 25, 2003 at 13:37 UTC
    It appears to be some kind of Windows family ID. The actual value appears to be meaningless, since WinCE definitely isn't of a higher level than Windows XP, for example.

    I interpret it as follows:
    0Windows 3.1, 3.11, WFWThe 16 bit Windows generation
    1Win95/98/MEWin95 and descendants
    2WinNT3.x, WinNT4.x, Win2k, WinXPthe NT family
    3WinCEWindows Control Edition, for handheld devices.

    I can't say I can even find a trace of it in Config.pm, nor in the \%Config hash it creates. I wouldn't trust those values anyway, as they are likely the values at the time perl was compiled. For example, on my system, $Config{osversion} is '4.0', even though I'm on Win98. As you can see, I should have gotten '4.1' or '4.10'.

    I think using an API call, through Win32::API, would be the safest way. As for which API call... there is GetVersion(). You'll get the value of the last column, live this time, and at least one bit saying whether this is NT or not. But still, GetVersionEx() looks like the better choice.

    use Win32::API; my $tpl = 'V5Z128'; my $struc = pack $tpl, 5*4+128, (0) x 4, ''; my $GetVersionEx = new Win32::API('kernel32', 'GetVersionExA', ['P'], +'N'); $GetVersionEx->Call($struc); my($OSVersionInfoSize, $MajorVersion, $MinorVersion, $BuildNumber, $Pl +atformId, $CSDVersion) = unpack $tpl, $struc; print << "END"; major: $MajorVersion minor: $MinorVersion build: $BuildNumber platform: $PlatformId "$CSDVersion" END
      s/Windows Control Edition/Windows Compact Edition/;
      :)