I was wondering if anyone knows of a good Perl method/module for detecting what Windows platform/version a Perl program is running under (the program will be Perl2exe compiled). I've done several searches here and on The Perl CD Bookshelf without finding anything consistent for the Win32 platforms.

I started out looking at $^O, but it: "Contains the name of the operating system that the current Perl binary was compiled for." (from Perl in a Nutshell). Besides the value returned in my particular test program under Win98 was "MSWin32" which is not nearly specific enough.

Then I looked through Learning Perl on Win32 Systems at the Win32::Registry modules, but there are too many inconsistencies between OS registry structures.

After much frustration with Win NT 4.0, I typed the DOS VER command from a DOS shell and thought "Hmm ..., this might work". Then I tested VER on Win95/98/2k machines and discovered that I could use them as well. So far I have the following snippet:

my $ver_str = `ver`; # Test strings # my $ver_str = 'Windows 98 [Version 4.10.1998]'; # my $ver_str = 'Microsoft Windows 2000 [Version 5.00.2195]'; # my $ver_str = 'Microsoft Windows 95. [Version 4.00.1111]'; ## guessed on this one ## my $ver_str = 'Windows NT Version 3.51'; # my $ver_str = 'Windows NT Version 4.0'; print "VER: $ver_str\n"; $_ = $ver_str; my $os_ver = "N/A"; $os_ver = 'win95' if m/( 95 | 95. )/; $os_ver = 'win98' if m/ 98 /; $os_ver = 'nt351' if m/ NT / && m/ 3.51/; $os_ver = 'nt40' if m/ NT / && m/ 4.0/; $os_ver = 'win2k' if m/ 2000 /; print "\$os_ver: $os_ver\n\n";
Since I don't have access to an NT 3.51 machine, I guessed at that one. I also need an example for Win ME as well but I can get that later at work.

The problems that I see now are:

So if anyone here at the Monastery has any reasonable ideas or suggestions I love to ++ them for it. Thanks.

P.S., this is related to my node Small Project Definition.

"The reward of a thing well done, is to have to done it." -- Ralph Waldo Emerson


In reply to Windows Version Detection by jlongino

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.