Subject: | Using Win32.pm on Windows 2012 results in "Unknown Windows version [2:6:2]" warning |
Using Strawberry Perl 5.16.1.1 (problem exists in 5.16.2.1 as well), Win32.pm doesn't support Windows Server 2012 and
produces the following error:
Unknown Windows version [2:6:2] at C:/temp/strawberry-perl-5.16.1.1/perl/lib/Win32.pm line 530.
A simple script demonstrates the error I see:
use Win32;
my ( $os_name, undef ) = Win32::GetOSName();
die "os_name undef!" unless (defined $os_name);
print "os_name: $os_name\n";
---
Prior to patching Win32.pm, the output on a Windows Server 2012 system is as follows:
Show quoted text
>perl win2012_demo.pl
Unknown Windows version [2:6:2] at C:/temp/strawberry-perl-5.16.1.1/perl/lib/Win32.pm line 530.
os_name undef! at win2012_demo.pl line 9.
By applying the attached patch, I'm able to successfully execute my script:
Show quoted text>perl win2012_demo.pl
os_name: Win2012
---
I've also included test cases in the patch for Windows 2012 Standard and Datacenter as well as Windows 8 and Windows 8
Professional.
Thanks
-Tim
Subject: | Win2012_Win8.patch |
Index: t/GetOSName.t
===================================================================
--- t/GetOSName.t (revision 566)
+++ t/GetOSName.t (working copy)
@@ -56,6 +56,9 @@
["2003 [Datacenter x64 Edition]", "2003", 2, 5, 2, 0x0080, 2, 0],
["2003 [Enterprise x64 Edition]", "2003", 2, 5, 2, 0x0002, 2, 0],
["2003 [Standard x64 Edition]", "2003", 2, 5, 2, 0x0000, 2, 0],
+
+["2012 [Datacenter]", "2012", 2, 6, 2, 0x0008, 2, ],
+["2012 [Standard]", "2012", 2, 6, 2, 0x0007, 2, ],
);
my @dual_tests = (
@@ -99,6 +102,8 @@
["7 [Enterprise]", "7", 2, 6, 1, 0x04 ],
["7 [Ultimate]", "7", 2, 6, 1, 0x01 ],
+["8", "8", 2, 6, 2 ],
+["8 [Professional]", "8", 2, 6, 2, 0x30 ],
["2008 [R2]", "2008", 2, 6, 1, 0x00, 2, 89 ],
["[Small Business Server] 2008 R2", "2008", 2, 6, 1, 0x09, 2, 89 ],
@@ -127,7 +132,7 @@
# and 2003/2008 start with "Windows Server"
unless ($pretty eq "Win32s") {
my $prefix = "Windows";
- $prefix .= " Server" if $pretty =~ /^200[38]/;
+ $prefix .= " Server" if $pretty =~ /^20(03|08|12)/;
$pretty = "$prefix $pretty";
}
Index: Win32.pm
===================================================================
--- Win32.pm (revision 566)
+++ Win32.pm (working copy)
@@ -154,10 +154,10 @@
sub CSIDL_RESOURCES_LOCALIZED () { 0x0039 } # %windir%\Resources\<LangID>, for theme and other windows specific resources.
sub CSIDL_CDBURN_AREA () { 0x003B } # <user name>\Local Settings\Application Data\Microsoft\CD Burning
-sub VER_NT_DOMAIN_CONTROLLER () { 0x0000002 } # The system is a domain controller and the operating system is Windows Server 2008, Windows Server 2003, or Windows 2000 Server.
-sub VER_NT_SERVER () { 0x0000003 } # The operating system is Windows Server 2008, Windows Server 2003, or Windows 2000 Server.
+sub VER_NT_DOMAIN_CONTROLLER () { 0x0000002 } # The system is a domain controller and the operating system is Windows Server 2012, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, or Windows 2000 Server.
+sub VER_NT_SERVER () { 0x0000003 } # The operating system is Windows Server 2012, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, or Windows 2000 Server.
# Note that a server that is also a domain controller is reported as VER_NT_DOMAIN_CONTROLLER, not VER_NT_SERVER.
-sub VER_NT_WORKSTATION () { 0x0000001 } # The operating system is Windows Vista, Windows XP Professional, Windows XP Home Edition, or Windows 2000 Professional.
+sub VER_NT_WORKSTATION () { 0x0000001 } # The operating system is Windows 8, Windows 7, Windows Vista, Windows XP Professional, Windows XP Home Edition, or Windows 2000 Professional.
sub VER_SUITE_BACKOFFICE () { 0x00000004 } # Microsoft BackOffice components are installed.
@@ -292,7 +292,7 @@
$desc =~ s/^\s*//;
s/(200.)/$name Server $1/;
}
- s/^Windows (200[38])/Windows Server $1/;
+ s/^Windows (20(03|08|12))/Windows Server $1/;
}
}
$name .= " $desc" if length $desc;
@@ -460,6 +460,14 @@
$desc = "R2";
}
}
+ elsif ($minor == 2) {
+ if ($producttype == VER_NT_WORKSTATION) {
+ $os = "8";
+ }
+ else {
+ $os = "2012";
+ }
+ }
if ($productinfo == PRODUCT_ULTIMATE) {
$desc .= " Ultimate";
@@ -860,6 +868,7 @@
Windows Server 2003 Enterprise Edition for Itanium-based Systems
Windows Vista Ultimate (32-bit)
Windows Small Business Server 2008 R2 (64-bit)
+ Windows Server 2012 Standard (64-bit)
The display name describes the native Windows version, so even on a
32-bit Perl this function may return a "Windows ... (64-bit)" name
@@ -899,6 +908,8 @@
WinVista
Win2008
Win7
+ Win8
+ Win2012
This routine is just a simple interface into GetOSVersion(). More
specific or demanding situations should use that instead. Another
@@ -921,8 +932,8 @@
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/Me and 2 for
-Windows NT/2000/XP/2003/Vista/2008/7. In scalar context it returns just
-the ID.
+Windows NT/2000/XP/2003/Vista/2008/7/2012/8. In scalar context it
+returns just the ID.
Currently known values for ID MAJOR and MINOR are as follows:
@@ -945,6 +956,8 @@
Windows Server 2008 2 6 0
Windows 7 2 6 1
Windows Server 2008 R2 2 6 1
+ Windows 8 2 6 2
+ Windows Server 2012 2 6 2
On Windows NT 4 SP6 and later this function returns the following
additional values: SPMAJOR, SPMINOR, SUITEMASK, PRODUCTTYPE.
@@ -961,6 +974,10 @@
identical; the PRODUCTTYPE field must be used to differentiate between
them.
+The version numbers for Windows 8 and Windows Server 2012 are
+identical; the PRODUCTTYPE field must be used to differentiate between
+them.
+
SPMAJOR and SPMINOR are are the version numbers of the latest
installed service pack.