Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WIX Toolset - Custom Action command doesn't correctly detect Windows 10 version

I have an installer that deploys and runs a separate .exe file to deploy drivers to a system. Unfortunately, Microsoft seems to have dropped support for the VersionNT macro in Windows 10 and onward, so I implemented an approach suggested in another post: write a function to query kernel32.dll for its version number, and compare against a sentinel value (10.0.10240.16384).

Here's the catch: when I run this command directly from an Administrative Console, the command correctly detects the version of Windows I'm running.

Current Windows Version: 10.0.10240.16384 - Cutoff Version: 10.0.10240.16384

However, when the command is executed as a Custom Action from my WIX Toolset installer, it seems to think I'm using an older version of Windows. My best guess at this point is the installer or the Custom Action command running in some sort of automatic compatibility mode.

Current Windows Version: 6.2.10240.16384 - Cutoff Version: 10.0.10240.16384

How can I proceed? The VersionNT abandonment is frustrating as it is, with the new version API (ie: IsWindows10OrGreater()) only available on Win10 or later, so on older machines I have to dlopen/dlsym and test for failures. I don't know why it's so hard to create a simple int return_OS_Version(major, minor, release, revision,) function.

like image 804
Ill Tempered Sea Bass Avatar asked Jul 05 '26 12:07

Ill Tempered Sea Bass


1 Answers

It is also possible to detect Windows 10 using RegistrySearch. For instance the node HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsNT\CurrentVersion contains the CurrentBuild and CurrentBuildNumber values. For Windows 8.1 or Windows Server 2012R2 these values are 9600 and for Windows 10 they will most probably be 14393.

<Property Id="WINDOWSBUILDNUM" Secure="yes">
  <RegistrySearch Id="YOUR_ID_HERE" Root="HKLM" Key="SOFTWARE\Microsoft\Windows NT\CurrentVersion" Name="CurrentBuild" Type="raw" />
</Property>

Having got a value one can handle it like this, in order to install a specific for Windows 10 file:

<Component Id="YOUR_ID_HERE" Guid="YOUR_GUID_HERE" DiskId="1">
    <Condition><![CDATA[Installed OR (WINDOWSBUILDNUM > 9999)]]></Condition>
    <File Id="YOUR_ID_HERE" Name="Api.dll" Source="$(var.SolutionDir)\TheRestOfThePath\Api_for_win_10.dll"/>        
</Component>
like image 61
Tariel Avatar answered Jul 08 '26 09:07

Tariel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!