How to programmatically detect and locate the Windows 10 SDK?
<h2>TL;DR</h2>

<p>Is there a Windows registry key (or other easily-programmable way) to find &amp; detect the Windows SDK, which works for SDK V10.0?</p>

<hr>

<p>I am doing something similar to <a href="https://stackoverflow.com/questions/14897750/automate-xsd-exe-during-build">this</a>, <em>i.e.</em> making use of some of the tooling accompanying the <a href="https://dev.windows.com/en-us/downloads/windows-10-sdk" rel="noreferrer">Windows 10 SDK</a>.</p>

<p>I am looking for a <strong>programatic way to detect and locate the Windows SDK</strong>.  This technique must work for (at least) version 10.0 (current as of this question).  Preferably, I would like a technique that works for all versions (and world peace would be nice too).</p>

<p><a href="https://en.wikipedia.org/wiki/Microsoft_Windows_SDK#Versions" rel="noreferrer">Previous versions</a> (at least up to V8.1A - as was included with Visual Studio 2013) were detectable via the windows registry.
(Although V&lt;7.0 <a href="https://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/6eb56ae2-831f-475f-b0c9-97aa7de53add/how-to-detect-installation-directory-of-windows-sdk-or-psdk?forum=windowssdk" rel="noreferrer">may not have been</a>).</p>

<p>For 64-bit installations:
<code>HKEY_LOCAL_MACHINE\SOFTWARE\</code><strong>Wow6432Node</strong><code>\Microsoft\Microsoft SDKs\Windows</code> (note the bolded difference from 32-bit).</p>

<p>While for 32-bit installs:
<code>HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows</code>, and <code>HKEY_CURRENT_USER\SOFTWARE\Microsoft\Microsoft SDKs\Windows</code></p>

<p>(More on that at the <a href="http://blogs.msdn.com/b/windowssdk/archive/2008/05/29/windows-sdk-registry-keys.aspx" rel="noreferrer">MSDN Windows SDK blog</a>).</p>

<p><strong>However</strong>, V10.0 (or V10.0A as is included with Visual Studio 2015) <em>does not</em> make a registry key as did previous versions!</p>

<p>There are techniques <a href="https://stackoverflow.com/questions/2665755/how-can-i-determine-the-version-of-the-windows-sdk-installed-on-my-computer">using compiler macros</a> to <em>detect</em> the SDK version.  However, these are not practical simply for SDK tool use (xsd.exe, etc), as they would require an entire compilation step - AND this would not necessarily yield a path to the SDK's tool directory!</p>

<p>Ideally, this should be achievable using PowerShell or a batch script or some other simple means that can be included in a build script or other automated environment (they are programming tools after all).</p>

<hr>

<h2>Note:</h2>

<p><strong><em>Yes</em></strong> there are ways to do this by interrogating the <em>file-system</em>, (<em>i.e.</em> programmatically listing subdirectories of <code>%ProgramFiles(x86)%\Microsoft SDKs\Windows\</code>, parsing out the 'V' and 'A'-s and selecting the <code>max()</code> of the numbers listed (10.0, etc)...</p>

<p><strong>HOWEVER</strong>, these approaches have a number of drawbacks:</p>

<ol>
<li>Quite clunky (filesystem access, string parsing, etc)</li>
<li>Error prone, an empty folder leftover from an incorrectly uninstalled SDK could brake said clunky directory parsing.</li>
<li>Subject to path differences, by platform (<em>i.e.</em> <code>%ProgramFiles(x86)%</code> on x64, but <code>%ProgramFiles%</code> on 32-bit), and by SDK version; SDK&lt;7 locates tooling inside a <code>Bin</code> directory, while SDK>7 uses <code>bin\NETFX X.X tools</code> (note the lowercase 'b', just for added inconsistency).</li>
<li>Also subject to user installation choices ("clever" sys admin installed the SDK in C:\Stuff\WinSDK\V10.0\, for example).</li>
</ol>

<p>Hence it would be <strong>MUCH</strong> better to achieve this programmatically, such as via the registry (as is <a href="http://blogs.msdn.com/b/windowssdk/archive/2008/05/29/windows-sdk-registry-keys.aspx" rel="noreferrer">possible for previous Windows SDK versions</a>)</p>

<hr>

<p>This question is not a duplicate of <a href="https://stackoverflow.com/questions/22975031/where-to-find-xsd-exe-in-visual-studio-2013-on-windows-8">this one</a>, as <em>this question</em> is both asking about a different SDK version, and is also asking about a <strong>programmatic</strong> (<em>i.e.</em> registry, etc) way to find the SDK path.</p>

<p>Nor is it a duplicate of <a href="https://stackoverflow.com/questions/34028259/cmake-windows-10-sdk">this</a>, as <em>that question</em> was dealing specifically with cmake and involved a build-number mismatch.</p>