Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for revision part of Windows build numbers (aka UBR, "Update Build Revision") #41

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Win32.pm
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ package Win32;
);
@EXPORT_OK = qw(
GetOSName
GetOSFullVersion
SW_HIDE
SW_SHOWNORMAL
SW_SHOWMINIMIZED
Expand Down Expand Up @@ -378,6 +379,14 @@ sub GetOSDisplayName {
return $name;
}

sub GetOSFullVersion {
my(undef, $major, $minor, $build) = Win32::GetOSVersion();
my @os_full_version = ($major, $minor, $build);
my $rev = Win32::GetOSUpdateBuildRevision();
push(@os_full_version, $rev) if(defined $rev);
return wantarray ? @os_full_version : join('.',@os_full_version);
}

sub _GetSystemMetrics {
my($index,$metrics) = @_;
return Win32::GetSystemMetrics($index) unless ref $metrics;
Expand Down Expand Up @@ -596,6 +605,8 @@ sub _GetOSName {
}
else {
$desc = " Build $build";
my $ubr = Win32::GetOSUpdateBuildRevision();
$desc.=".$ubr" if(defined $ubr);
}
}
else {
Expand All @@ -620,6 +631,8 @@ sub _GetOSName {
}
else {
$desc = "Build $build";
my $ubr = Win32::GetOSUpdateBuildRevision();
$desc.=".$ubr" if(defined $ubr);
}
}
}
Expand Down Expand Up @@ -1092,6 +1105,15 @@ Win32::GetProductInfo() and Win32::GetSystemMetrics() functions provide
the base information to check for certain capabilities, or for families
of OS releases.

=item Win32::GetOSFullVersion()

In scalar context returns a string containing the full version of the
Win32 operating system (including revision number if applicable), in
following format: C<major.minor.build.revision> (example for Windows 10
version 22H2 build 19045.4170: C<"10.0.19045.4170">). In list context
returns the same numbers in a list instead:
C<($major, $minor, $build, $revision)> (example: C<(10, 0, 19045, 4170)>).

=item Win32::GetOSName()

In scalar context returns the name of the Win32 operating system
Expand Down Expand Up @@ -1144,6 +1166,13 @@ different major/minor version number than Windows XP.
Similarly the name "WinWin32s" should have been "Win32s" but has been
kept as-is for backwards compatibility reasons too.

=item Win32::GetOSUpdateBuildRevision()

Returns the current Update Build Revision (UBR) of the Win32 operating
system if applicable, or undef otherwise. The UBR number is the last
part of the build numbers used by Microsoft to identify the exact
Windows revisions.

=item Win32::GetOSVersion()

[CORE] Returns the list (STRING, MAJOR, MINOR, BUILD, ID), where the
Expand Down
35 changes: 35 additions & 0 deletions Win32.xs
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,40 @@ XS(w32_GetOSVersion)
PUTBACK;
}

XS(w32_GetOSUpdateBuildRevision)
{
dXSARGS;
LONG status;
DWORD val, val_size = sizeof(val);
PFNRegGetValueA pfnRegGetValueA;
HMODULE module;

if (items)
Perl_croak(aTHX_ "usage: Win32::GetOSUpdateBuildRevision()");

EXTEND(SP, 1);

module = GetModuleHandleA("advapi32.dll");
GETPROC(RegGetValueA);
if (!pfnRegGetValueA)
XSRETURN_UNDEF;

status = pfnRegGetValueA(
HKEY_LOCAL_MACHINE,
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",
"UBR",
RRF_RT_REG_DWORD,
NULL,
&val,
&val_size
);

if (status == ERROR_SUCCESS)
XSRETURN_IV(val);

XSRETURN_UNDEF;
}

XS(w32_IsWinNT)
{
dXSARGS;
Expand Down Expand Up @@ -2058,6 +2092,7 @@ BOOT:
newXS("Win32::DomainName", w32_DomainName, file);
newXS("Win32::FsType", w32_FsType, file);
newXS("Win32::GetOSVersion", w32_GetOSVersion, file);
newXS("Win32::GetOSUpdateBuildRevision", w32_GetOSUpdateBuildRevision, file);
newXS("Win32::IsWinNT", w32_IsWinNT, file);
newXS("Win32::IsWin95", w32_IsWin95, file);
newXS("Win32::FormatMessage", w32_FormatMessage, file);
Expand Down