Skip to content

Commit 57ca47d

Browse files
committed
Improve GetOSDisplaName for Windows 10 and WIndows 2016+ Server releases
Add a few missing releases. Identify preview release (and include build numbers). Don't apply "productinfo" based labels on Win10 releases. Fix tests.
1 parent 6cc5e74 commit 57ca47d

File tree

2 files changed

+173
-105
lines changed

2 files changed

+173
-105
lines changed

Win32.pm

Lines changed: 127 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ sub GetOSDisplayName {
361361
s/(200.)/$name Server $1/;
362362
}
363363
s/^Windows (20(03|08|12|16|19))/Windows Server $1/;
364-
s/^Windows SAC/Windows Server/;
364+
s/^Windows SAC/Windows Server/;
365365
}
366366
}
367367
$name .= " $desc" if length $desc;
@@ -530,12 +530,12 @@ sub _GetOSName {
530530
}
531531
}
532532
elsif ($minor == 2) {
533-
if ($producttype == VER_NT_WORKSTATION) {
534-
$os = "8";
535-
}
536-
else {
537-
$os = "2012";
538-
}
533+
if ($producttype == VER_NT_WORKSTATION) {
534+
$os = "8";
535+
}
536+
else {
537+
$os = "2012";
538+
}
539539
}
540540
elsif ($minor == 3) {
541541
if ($producttype == VER_NT_WORKSTATION) {
@@ -546,100 +546,132 @@ sub _GetOSName {
546546
$desc = "R2";
547547
}
548548
}
549-
}
549+
}
550550
elsif ($major == 10) {
551-
if ($producttype == VER_NT_WORKSTATION) {
552-
$os = '10';
553-
if ($build == 10240) {
554-
$desc = ", version 1507 (RTM)";
555-
} elsif ($build == 14393) {
556-
$desc = ", version 1607";
557-
} elsif ($build == 15063) {
558-
$desc = ", version 1703";
559-
} elsif ($build == 16299) {
560-
$desc = ", version 1709";
561-
} elsif ($build == 17134) {
562-
$desc = ", version 1803";
563-
} elsif ($build == 17763) {
564-
$desc = ", version 1809";
565-
} else {
566-
$desc = ", version <unknown>";
551+
if ($producttype == VER_NT_WORKSTATION) {
552+
# Build numbers from https://en.wikipedia.org/wiki/Windows_10_version_history
553+
$os = '10';
554+
if (9841 <= $build && $build <= 10240) {
555+
$desc = " Version 1507";
556+
$desc .= " (Preview Build $build)" if $build < 10240;
557+
$desc .= " (RTM)" if $build == 10240;
558+
}
559+
elsif (10525 <= $build && $build <= 10586) {
560+
$desc = " Version 1511 (November Update)";
561+
$desc .= " (Preview Build $build)" if $build < 10586;
562+
}
563+
elsif (11082 <= $build && $build <= 14393) {
564+
$desc = " Version 1607 (Anniversary Update)";
565+
$desc .= " (Preview Build $build)" if $build < 14393;
566+
}
567+
elsif (14901 <= $build && $build <= 15063) {
568+
$desc = " Version 1703 (Creators Update)";
569+
$desc .= " (Preview Build $build)" if $build < 15063;
570+
}
571+
elsif (16170 <= $build && $build <= 16299) {
572+
$desc = " Version 1709 (Fall Creators Update)";
573+
$desc .= " (Preview Build $build)" if $build < 16299;
574+
}
575+
elsif (16353 <= $build && $build <= 17134) {
576+
$desc = " Version 1803 (April 2018 Update)";
577+
$desc .= " (Preview Build $build)" if $build < 17134;
578+
}
579+
elsif (17604 <= $build && $build <= 17763) {
580+
$desc = " Version 1809 (October 2018 Update)";
581+
$desc .= " (Preview Build $build)" if $build < 17763;
582+
}
583+
elsif (18204 <= $build && $build <= 18362) {
584+
$desc = " Version 1903 (May 2019 Update)";
585+
$desc .= " (Preview Build $build)" if $build < 18362;
586+
}
587+
else {
588+
$desc = " Build $build";
589+
}
567590
}
568-
} else {
569-
if ($build == 14393) {
570-
$os = "2016";
571-
$build = ", version 1607";
572-
} elsif ($build == 17763) {
573-
$os = "2019";
574-
$build = ", version 1809";
575-
} else {
576-
$os = "SAC";
577-
if ($build == 16299) {
578-
$desc = ", version 1709";
579-
} elsif ($build == 17134) {
580-
$desc = ", version 1803";
581-
} else {
582-
$desc = ", version <unknown>";
591+
else {
592+
if ($build == 14393) {
593+
$os = "2016";
594+
$desc = "Version 1607";
595+
}
596+
elsif ($build == 17763) {
597+
$os = "2019";
598+
$desc = "Version 1809";
599+
}
600+
else {
601+
$os = "Server";
602+
if ($build == 16299) {
603+
$desc = "Version 1709";
604+
}
605+
elsif ($build == 17134) {
606+
$desc = "Version 1803";
607+
}
608+
elsif ($build == 18362) {
609+
$desc = "Version 1903";
610+
}
611+
else {
612+
$desc = "Build $build";
613+
}
583614
}
584615
}
585616
}
586-
}
587617

588618
if ($major >= 6) {
589-
if ($productinfo == PRODUCT_ULTIMATE) {
590-
$desc .= " Ultimate";
591-
}
592-
elsif ($productinfo == PRODUCT_HOME_PREMIUM) {
593-
$desc .= " Home Premium";
594-
}
595-
elsif ($productinfo == PRODUCT_HOME_BASIC) {
596-
$desc .= " Home Basic";
597-
}
598-
elsif ($productinfo == PRODUCT_ENTERPRISE) {
599-
$desc .= " Enterprise";
600-
}
601-
elsif ($productinfo == PRODUCT_BUSINESS) {
602-
# "Windows 7 Business" had a name change to "Windows 7 Professional"
603-
$desc .= $minor == 0 ? " Business" : " Professional";
604-
}
605-
elsif ($productinfo == PRODUCT_STARTER) {
606-
$desc .= " Starter";
607-
}
608-
elsif ($productinfo == PRODUCT_CLUSTER_SERVER) {
609-
$desc .= " HPC Server";
610-
}
611-
elsif ($productinfo == PRODUCT_DATACENTER_SERVER) {
612-
$desc .= " Datacenter";
613-
}
614-
elsif ($productinfo == PRODUCT_DATACENTER_SERVER_CORE) {
615-
$desc .= " Datacenter Edition (core installation)";
616-
}
617-
elsif ($productinfo == PRODUCT_ENTERPRISE_SERVER) {
618-
$desc .= " Enterprise";
619-
}
620-
elsif ($productinfo == PRODUCT_ENTERPRISE_SERVER_CORE) {
621-
$desc .= " Enterprise Edition (core installation)";
622-
}
623-
elsif ($productinfo == PRODUCT_ENTERPRISE_SERVER_IA64) {
624-
$desc .= " Enterprise Edition for Itanium-based Systems";
625-
}
626-
elsif ($productinfo == PRODUCT_SMALLBUSINESS_SERVER) {
627-
$desc .= " Small Business Server";
628-
}
629-
elsif ($productinfo == PRODUCT_SMALLBUSINESS_SERVER_PREMIUM) {
630-
$desc .= " Small Business Server Premium Edition";
631-
}
632-
elsif ($productinfo == PRODUCT_STANDARD_SERVER) {
633-
$desc .= " Standard";
634-
}
635-
elsif ($productinfo == PRODUCT_STANDARD_SERVER_CORE) {
636-
$desc .= " Standard Edition (core installation)";
637-
}
638-
elsif ($productinfo == PRODUCT_WEB_SERVER) {
639-
$desc .= " Web Server";
640-
}
641-
elsif ($productinfo == PRODUCT_PROFESSIONAL) {
642-
$desc .= " Professional";
619+
if ($major == 6) {
620+
if ($productinfo == PRODUCT_ULTIMATE) {
621+
$desc .= " Ultimate";
622+
}
623+
elsif ($productinfo == PRODUCT_HOME_PREMIUM) {
624+
$desc .= " Home Premium";
625+
}
626+
elsif ($productinfo == PRODUCT_HOME_BASIC) {
627+
$desc .= " Home Basic";
628+
}
629+
elsif ($productinfo == PRODUCT_ENTERPRISE) {
630+
$desc .= " Enterprise";
631+
}
632+
elsif ($productinfo == PRODUCT_BUSINESS) {
633+
# "Windows 7 Business" had a name change to "Windows 7 Professional"
634+
$desc .= $minor == 0 ? " Business" : " Professional";
635+
}
636+
elsif ($productinfo == PRODUCT_STARTER) {
637+
$desc .= " Starter";
638+
}
639+
elsif ($productinfo == PRODUCT_CLUSTER_SERVER) {
640+
$desc .= " HPC Server";
641+
}
642+
elsif ($productinfo == PRODUCT_DATACENTER_SERVER) {
643+
$desc .= " Datacenter";
644+
}
645+
elsif ($productinfo == PRODUCT_DATACENTER_SERVER_CORE) {
646+
$desc .= " Datacenter Edition (core installation)";
647+
}
648+
elsif ($productinfo == PRODUCT_ENTERPRISE_SERVER) {
649+
$desc .= " Enterprise";
650+
}
651+
elsif ($productinfo == PRODUCT_ENTERPRISE_SERVER_CORE) {
652+
$desc .= " Enterprise Edition (core installation)";
653+
}
654+
elsif ($productinfo == PRODUCT_ENTERPRISE_SERVER_IA64) {
655+
$desc .= " Enterprise Edition for Itanium-based Systems";
656+
}
657+
elsif ($productinfo == PRODUCT_SMALLBUSINESS_SERVER) {
658+
$desc .= " Small Business Server";
659+
}
660+
elsif ($productinfo == PRODUCT_SMALLBUSINESS_SERVER_PREMIUM) {
661+
$desc .= " Small Business Server Premium Edition";
662+
}
663+
elsif ($productinfo == PRODUCT_STANDARD_SERVER) {
664+
$desc .= " Standard";
665+
}
666+
elsif ($productinfo == PRODUCT_STANDARD_SERVER_CORE) {
667+
$desc .= " Standard Edition (core installation)";
668+
}
669+
elsif ($productinfo == PRODUCT_WEB_SERVER) {
670+
$desc .= " Web Server";
671+
}
672+
elsif ($productinfo == PRODUCT_PROFESSIONAL) {
673+
$desc .= " Professional";
674+
}
643675
}
644676

645677
if ($arch == PROCESSOR_ARCHITECTURE_INTEL) {
@@ -648,7 +680,7 @@ sub _GetOSName {
648680
elsif ($arch == PROCESSOR_ARCHITECTURE_AMD64) {
649681
$desc .= " (64-bit)";
650682
}
651-
}
683+
}
652684
}
653685

654686
unless (defined $os) {

t/GetOSName.t

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,50 @@ my @dual_tests = (
100100
["7 [Ultimate]", "7", 2, 6, 1, 0x01 ],
101101

102102
["8", "8", 2, 6, 2 ],
103-
["2008 [R2]", "2008", 2, 6, 1, 0x00, 2, 89 ],
104-
["2012", "2012", 2, 6, 2, 0x00, 2, 89 ],
103+
["2008 [R2 Standard]", "2008", 2, 6, 1, 0x07, 2, 89 ],
104+
["2012 [Standard]", "2012", 2, 6, 2, 0x07, 2, 89 ],
105105
["[Small Business Server] 2008 R2", "2008", 2, 6, 1, 0x09, 2, 89 ],
106106

107107
["8.1", "8.1", 2, 6, 3 ],
108108
["2012 [R2]", "2012", 2, 6, 3, 0x00, 2, 89 ],
109+
);
110+
111+
my @win10_tests = (
112+
["10 [Build 9840]", "10", 2, 10, 0, 0x00, 0, 0, 9840],
113+
114+
["10 [Version 1507 (Preview Build 9841)]", "10", 2, 10, 0, 0x00, 0, 0, 9841],
115+
["10 [Version 1507 (RTM)]", "10", 2, 10, 0, 0x00, 0, 0, 10240],
116+
117+
["10 [Version 1511 (November Update) (Preview Build 10525)]", "10", 2, 10, 0, 0x00, 0, 0, 10525],
118+
["10 [Version 1511 (November Update)]", "10", 2, 10, 0, 0x00, 0, 0, 10586],
119+
120+
["10 [Version 1607 (Anniversary Update) (Preview Build 11082)]", "10", 2, 10, 0, 0x00, 0, 0, 11082],
121+
["10 [Version 1607 (Anniversary Update)]", "10", 2, 10, 0, 0x00, 0, 0, 14393],
122+
123+
["10 [Version 1703 (Creators Update) (Preview Build 14901)]", "10", 2, 10, 0, 0x00, 0, 0, 14901],
124+
["10 [Version 1703 (Creators Update)]", "10", 2, 10, 0, 0x00, 0, 0, 15063],
109125

110-
["10", "10", 2, 10, 0, 0x00, 2, 89 ],
111-
["2016", "2016", 2, 10, 0, 0x00, 2, 89 ],
112-
["2019", "2019", 2, 10, 0, 0x00, 2, 89 ],
126+
["10 [Version 1709 (Fall Creators Update) (Preview Build 16170)]", "10", 2, 10, 0, 0x00, 0, 0, 16170],
127+
["10 [Version 1709 (Fall Creators Update)]", "10", 2, 10, 0, 0x00, 0, 0, 16299],
128+
129+
["10 [Version 1803 (April 2018 Update) (Preview Build 16353)]", "10", 2, 10, 0, 0x00, 0, 0, 16353],
130+
["10 [Version 1803 (April 2018 Update)]", "10", 2, 10, 0, 0x00, 0, 0, 17134],
131+
132+
["10 [Version 1809 (October 2018 Update) (Preview Build 17604)]", "10", 2, 10, 0, 0x00, 0, 0, 17604],
133+
["10 [Version 1809 (October 2018 Update)]", "10", 2, 10, 0, 0x00, 0, 0, 17763],
134+
135+
["10 [Version 1903 (May 2019 Update) (Preview Build 18204)]", "10", 2, 10, 0, 0x00, 0, 0, 18204],
136+
["10 [Version 1903 (May 2019 Update)]", "10", 2, 10, 0, 0x00, 0, 0, 18362],
137+
138+
["2016 [Version 1607]", "2016", 2, 10, 0, 0x07, 2, 0, 14393],
139+
["2019 [Version 1809]", "2019", 2, 10, 0, 0x07, 2, 0, 17763],
140+
141+
["Server [Version 1709]", "Server", 2, 10, 0, 0x07, 2, 0, 16299],
142+
["Server [Version 1803]", "Server", 2, 10, 0, 0x07, 2, 0, 17134],
143+
# The 1809 version from the semi-annual channel will identify as "Windows Server 2019 Version 1809"
144+
#["Server [Version 1809]", "Server", 2, 10, 0, 0x07, 2, 0, 17763],
145+
["Server [Version 1903]", "Server", 2, 10, 0, 0x07, 2, 0, 18362],
146+
["Server [Build 12345]", "Server", 2, 10, 0, 0x07, 2, 0, 12345],
113147

114148
);
115149

@@ -118,12 +152,12 @@ my @ia64_tests = (
118152
["2003 [Enterprise Edition for Itanium-based Systems]", "2003", 2, 5, 2, 0x0002, 2, 0],
119153
);
120154

121-
plan tests => 6 * (@intel_tests + @amd64_tests + 2*@dual_tests + @ia64_tests);
155+
plan tests => 6 * (@intel_tests + @amd64_tests + 2*@dual_tests + @ia64_tests) + 3 * @win10_tests;
122156

123157
# Test internal implementation function
124158
sub check {
125159
my($test, $arch) = @_;
126-
my($pretty, $expect, $id, $major, $minor, $sm, $pt, $metrics) = @$test;
160+
my($pretty, $expect, $id, $major, $minor, $sm, $pt, $metrics, $build) = @$test;
127161
$metrics = [$metrics] if defined($metrics) && not ref $metrics;
128162

129163
my $tag = "";
@@ -135,7 +169,7 @@ sub check {
135169
# and 2003/2008 start with "Windows Server"
136170
unless ($pretty eq "Win32s") {
137171
my $prefix = "Windows";
138-
$prefix .= " Server" if $pretty =~ /^20(03|08|12)/;
172+
$prefix .= " Server" if $pretty =~ /^20(03|08|12|16|19)/;
139173
$pretty = "$prefix $pretty";
140174
}
141175

@@ -150,7 +184,7 @@ sub check {
150184

151185
# We pass the same value for $suitemask and $productinfo. The former is
152186
# used for Windows up to 2003, the latter is used for Vista and later.
153-
my($os, $desc) = Win32::_GetOSName("", $major||0, $minor||0, 0,
187+
my($os, $desc) = Win32::_GetOSName("", $major||0, $minor||0, $build,
154188
$id, $sm||0, $pt||1, $sm||0, $arch, $metrics);
155189
my $display = Win32::GetOSDisplayName($os, $desc);
156190

@@ -159,6 +193,8 @@ sub check {
159193
is($os, "Win$expect", "os: $os");
160194
is($desc, $tag, "desc: $desc");
161195

196+
next if $major == 10;
197+
162198
my $sp = "Service Pack 42";
163199
($os, $desc) = Win32::_GetOSName($sp, $major||0, $minor||0, 0,
164200
$id, $sm||0, $pt||1, $sm||0, $arch, $metrics);
@@ -170,7 +206,7 @@ sub check {
170206
is($desc, $expect, "desc: $desc");
171207
}
172208

173-
check($_, Win32::PROCESSOR_ARCHITECTURE_INTEL) for @intel_tests, @dual_tests;
209+
check($_, Win32::PROCESSOR_ARCHITECTURE_INTEL) for @intel_tests, @dual_tests, @win10_tests;
174210
check($_, Win32::PROCESSOR_ARCHITECTURE_AMD64) for @amd64_tests, @dual_tests;
175211
check($_, Win32::PROCESSOR_ARCHITECTURE_IA64) for @ia64_tests;
176212

0 commit comments

Comments
 (0)