<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Red Pill BLOGS</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/hewagen/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/hewagen/feed.xml</link>
    <description>Windows 10 and custom coding. The answer to life, the universe and everything. By Helmut Wagensonner [PFE]</description>
    <lastBuildDate>Tue, 16 Apr 2019 05:09:14 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>PCRDump</title>
      <link>https://docs.microsoft.com/archive/blogs/hewagen/pcrdump</link>
      <pubDate>Sun, 13 May 2018 08:48:55 GMT</pubDate>
      <dc:creator><![CDATA[Helmut Wagensonner (MS)]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/hewagen/?p=235</guid>
      <description><![CDATA[When running into Bitlocker recovery issues I always used the tools PCPTool (written by Stefan Thom)...]]></description>
      <content:encoded><![CDATA[When running into Bitlocker recovery issues I always used the tools <strong>PCPTool</strong> (written by <em>Stefan Thom</em>) and <strong>Win7PCRv2</strong> (actually I couldn’t figure out who coded this one) to dump the TPM PCR registers. On some devices with newer Win 10 builds (1709 onwards) the tools were throwing errors. PCPTool complained about a too small buffer size while Win7PCRv2 came up with some System.Management errors. Additionally, it is a pain that Win7PCRv2 is compiled against .NET 2.0, which forces you to install .NET 3.5 on Win 10 clients first.

That’s why I decided to re-write the PCR dump functions of those tools and combine them into one executable. PCPTool utilizes ncrypt.dll to get the PCR values while Win7PCRv2 relies on TPM base service (tbs.dll), which is also available in Win7. I gave a bigger buffer to the NCryptGetProperty call and I forced the WMI functions to use more current Management classes to query the TPM spec version. Still I have no idea why a byte[24*20] is not enough buffer for 24 TPM registers with 20 bytes each. So the ncrypt way my return incorrect values in rare cases.

The result of it all is a new executable, which can query the PCR registers in two different ways. Also, it uses .NET 4.0 so there’s no need to install ancient frameworks.
At the moment, the command understands 3 parameters:

<ul>
	<li><em>-ncrypt</em>: forces the tool to query the PCR values using the NCryptGetProperty function of the ncrypt.dll (only available in Windows 10).</li>
	<li><em>-tbs</em>: forces the tool to query the PCR values using the Tbsip_Submit_Command function of the tbs.dll.</li>
	<li><em>-getpcr</em>: uses both methods. If the result is different, you can use the <em>-ncrypt -show48</em> parameters to dump the next 24 * 20 bytes. Show48 is for debug purposes only.</li>
</ul>
Use <strong><em>PCRDump -?</em></strong> to get a usage output. Note that you must run the tool in an elevated command prompt.
<br>
<a href="https://microsoft-my.sharepoint.com/:f:/g/personal/hewagen_microsoft_com1/EiNh6aJ0dbBNrftgRDQ1WIUBwD72Gk-2JEIAmtbZR9FvrQ?e=SSkzc1"><img src="https://msdnshared.blob.core.windows.net/media/2018/05/2018-05-13_09-43-541.png" alt="" width="220" height="52" class="alignnone size-full wp-image-265" /></a>

Clicking the <i>Download</i> button takes you to the OneDrive folder. You only need to download the PCRDump.exe file.
<strong><u>Note:</u> This download link is only available to Microsoft FTE’s at the moment.</strong> Non Microsoft FTE's can send a download request by e-mail.
]]></content:encoded>
    </item>
    <item>
      <title>Making file type associations enterprise ready</title>
      <link>https://docs.microsoft.com/archive/blogs/hewagen/making-file-type-associations-enterprise-ready</link>
      <pubDate>Sun, 11 Mar 2018 14:09:23 GMT</pubDate>
      <dc:creator><![CDATA[Helmut Wagensonner (MS)]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/hewagen/?p=155</guid>
      <description><![CDATA[You may have noticed already that file type association has changed fundamentally in Windows 10. It...]]></description>
      <content:encoded><![CDATA[You may have noticed already that file type association has changed fundamentally in Windows 10. It is no longer possible for Administrators to set the default application for a certain file type dynamically. The only remaining option is, to create an XML file containing the desired FTA’s and import it using DISM (only valid for new users) or apply it using GPO (valid for all users on a PC). <a href="https://blogs.technet.microsoft.com/windowsinternals/2017/10/25/windows-10-how-to-configure-file-associations-for-it-pros/" rel="noopener" target="_blank">Here’s a good technical explanation</a> about how FTA works in Windows 10.

The solution I’m providing here adds a bit of dynamics to the file type association topic (FTA). It is still a workaround but it lets you modify file type associations by using a Powershell script. Make sure to configure your environment as mentioned below.

<strong>Prepare your environment</strong>
<ul>
<li>Create a default file type association XML, which works with your standard client (click <a href="https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/export-or-import-default-application-associations" rel="noopener" target="_blank">here</a> to see how to export FTA's). Make sure that your FTA XML file only contains extensions you want to modify. Simply remove the lines with extensions you want to leave untouched. You can also deploy an empty XML if you don’t want to assign any file types yet. An empty file would look like this:
<code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;DefaultAssociations&gt;
&lt;/DefaultAssociations&gt;</code>
</li>
<li>
Use your preferred deployment method to push the file to your clients or add it to your master image. Select a local folder, which is readable but not changeable for users. The C:\ProgramData\<em>YourCompany</em> folder would be a good place. You can refer to it in the GPO with the <em>%ProgramData%</em> variable.
</li>
<li>
Create a GPO which affects all Windows 10 clients and change the setting as shown in the picture. Point the path to the location, where you copied your XML file.
<img src="https://msdnshared.blob.core.windows.net/media/2018/03/FTAGPO.png" alt="" width="741" height="209" class="alignnone size-full wp-image-175" />
</li>
</ul>
On a client, which is in scope of the GPO, do a GPUPDATE and log off/on to apply the changes. The settings of you FTA XML should now take effect.

You can check the registry for verification. If you changed, for example, the assignment for .AVI files in your config file, you should find a registry value <em>HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.avi\UserChoice\ProgId</em>. The data of this value should be the same as the <em>ProgId</em> specified in your XML. And of course .AVI files should open with the application you assigned it to. If this is not the case, check the event log <em>Microsoft-Windows-Shell-Core/AppDefaults</em> for errors.

<strong>Add script to application deployments</strong>

Let’s assume you deploy an application to a set of clients, which handles a file type you already assigned to an application in your XML. You want to change the default app for this file type. To accomplish this, simply run the Powershell script attached to this article after the installation of the new application. You can also make this part of your app deployment.

<code>Modify-AppAssocXml.ps1 -Path "C:\ProgramData\<em>YourCompany</em>\AppAssoc.xml" -Extension ".avi" -ProgId "VLC.avi" -AppName "VLC Media Player"</code>

This modifies the local application association XML file. It changes .AVI to the new AppId or adds a new line, if AVI is not yet assigned. To use this script, you should understand the values the command accepts.

<u>Path</u> is straightforward. It’s the path to your local FTA config file.
<u>Extension</u> is the file type(s) you want to modify or set. You can either specify a single extension or multiple extensions, separated by comma (i.e. ".avi,.mp4,.mpeg")
<u>ProgID</u> is the path to the open handler in the registry, relative from <em>HKEY_CLASSES_ROOT</em> to the key name before <em>Shell\Open\Command</em>. An Example: The open handler for “notepad.exe” can be found in <i>HKEY_CLASSES_ROOT\<font Color="red">Applications\notepad.exe</font>\shell\open\command</i>. The ProgID for Notepad would be <em>Applications\notepad.exe</em>.
<u>AppName</u> is the file description property of the corresponding EXE file. However, this value does not affect the file type association but it must be set.

Unfortunately, it requires GPO foreground processing for the settings to take effect. This means that users need to log off/on after the FTA XML has changed.
<br>
<a href="https://msdnshared.blob.core.windows.net/media/2018/03/Modify-AppAssocXml-1.21.zip"><img src="https://msdnshared.blob.core.windows.net/media/2018/03/Download_ModifyAppAssocXml.png" alt="" width="221" height="51" class="alignnone size-full wp-image-195" /></a>
]]></content:encoded>
    </item>
    <item>
      <title>Another Windows 10 version overview</title>
      <link>https://docs.microsoft.com/archive/blogs/hewagen/win10ver</link>
      <pubDate>Sat, 24 Feb 2018 12:43:50 GMT</pubDate>
      <dc:creator><![CDATA[Helmut Wagensonner (MS)]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/hewagen/?p=115</guid>
      <description><![CDATA[This overview combines information from different TechNet/Blog/Support pages to have the most...]]></description>
      <content:encoded><![CDATA[This overview combines information from different TechNet/Blog/Support pages to have the most interesting values in one table. I will maintain this page from time to time. However, it could happen that some values are outdated. If so, please leave a comment and I will update the table. Therefore, <em>always check the last modified date</em>.

Note, that dates are specified in German notation (dd.mm.yyyy).
<table border="1">
<tbody>
<tr align="center" bgcolor="#c0c0c0">
<td>Version</td>
<td>Code Name</td>
<td>Initial Build</td>
<td>Channel Switch</td>
<td>Current Channel</td>
<td>Release</td>
<td>Channel Switch</td>
<td>End of Support</td>
<td>Extended Support</td>
<td>.NET Runtime</td>
<td>Powershell</td>
</tr>
<tr>
<td>1507</td>
<td>Threshold</td>
<td>10240.16405</td>
<td>
<div id="notavailable">N/A</div></td>
<td>CBB</td>
<td>29.07.2015</td>
<td>
<div id="notavailable">N/A</div></td>
<td>
<div id="outofsupport">09.05.2017</div></td>
<td>
<div id="notavailable">N/A</div></td>
<td>4.6</td>
<td>5.0</td>
</tr>
<tr>
<td>1511</td>
<td>Threshold 2</td>
<td>10586.3</td>
<td>10586.164</td>
<td>CBB</td>
<td>10.11.2015</td>
<td>08.03.2016</td>
<td>
<div id="outofsupport">10.10.2017</div></td>
<td>
<div id="notavailable">N/A</div></td>
<td>4.6.1</td>
<td>5.1</td>
</tr>
<tr>
<td>1607</td>
<td>Redstone</td>
<td>14393.10</td>
<td>14393.447</td>
<td>CBB</td>
<td>02.08.2016</td>
<td>08.11.2016</td>
<td>09.04.2019</td>
<td><div id="notavailable">N/A</div></td>
<td>4.6.2</td>
<td>5.1</td>
</tr>
<tr>
<td>1703</td>
<td>Redstone 2</td>
<td>15063.138</td>
<td>15063.483</td>
<td>SAC</td>
<td>05.04.2017</td>
<td>11.07.2017</td>
<td>08.10.2019</td>
<td><div id="notavailable">N/A</div></td>
<td>4.7</td>
<td>5.1</td>
</tr>
<tr>
<td>1709</td>
<td>Redstone 3</td>
<td>16299.19</td>
<td>16299.125</td>
<td>SAC</td>
<td>17.10.2017</td>
<td>12.12.2017</td>
<td>10.04.2020</td>
<td><div id="notavailable">N/A</div></td>
<td>4.7.1</td>
<td>5.1</td>
</tr>
<tr>
<td>1803</td>
<td>Redstone 4</td>
<td>17134.1</td>
<td>17134.165</td>
<td>SAC</td>
<td>30.04.2018</td>
<td>10.07.2018</td>
<td>10.11.2020</td>
<td>
<div id="notavailable">N/A</div></td>
<td>4.7.2 (Rel 461814)</td>
<td>5.1</td>
</tr>
<tr>
<td>1809</td>
<td>Redstone 5</td>
<td>17763.1</td>
<td>
<div id="notavailable">N/A</div></td>
<td>SAC-T</td>
<td>02.10.2018</td>
<td>
<div id="notavailable">N/A</div></td>
<td>13.04.2021</td>
<td>
<div id="notavailable">N/A</div></td>
<td>4.7.2 (Rel 461814)</td>
<td>5.1</td>
</tr>
<tr>
<td>1903</td>
<td>19H1</td>
<td>
<div id="notavailable">N/A</div></td>
<td>
<div id="notavailable">N/A</div></td>
<td>Skip-Ahead</td>
<td>
<div id="notavailable">N/A</div></td>
<td>
<div id="notavailable">N/A</div></td>
<td>
<div id="notavailable">N/A</div></td>
<td>
<div id="notavailable">N/A</div></td>
<td>
<div id="notavailable">N/A</div></td>
<td>
<div id="notavailable">N/A</div></td>
</tr>
<tr>
<td>1507 LTSB</td>
<td>Threshold</td>
<td>10240.16405</td>
<td>
<div id="notavailable">N/A</div></td>
<td>LTSB</td>
<td>29.07.2015</td>
<td>
<div id="notavailable">N/A</div></td>
<td>13.10.2020</td>
<td>14.10.2025</td>
<td>4.6</td>
<td>5.0</td>
</tr>
<tr>
<td>1607 LTSB</td>
<td>Redstone</td>
<td>14393.10</td>
<td>
<div id="notavailable">N/A</div></td>
<td>LTSB</td>
<td>02.08.2016</td>
<td>
<div id="notavailable">N/A</div></td>
<td>12.10.2021</td>
<td>13.10.2026</td>
<td>4.6.2</td>
<td>5.1</td>
</tr>
<tr>
<td>1809 LTSC</td>
<td>Redstone 5</td>
<td>
<div id="notavailable">N/A</div></td>
<td>
<div id="notavailable">N/A</div></td>
<td>
<div id="notavailable">N/A</div></td>
<td>Fall 2018</td>
<td>
<div id="notavailable">N/A</div></td>
<td>
<div id="notavailable">N/A</div></td>
<td>
<div id="notavailable">N/A</div></td>
<td>
<div id="notavailable">N/A</div></td>
<td>
<div id="notavailable">N/A</div></td>
</tr>
</tbody>
</table>
<br>Most columns don't need to be explained. The <strong>Channel Switch</strong> column, which appears twice, specifies the version and the date of the CBB/SAC declaration for each release. Further information on servicing channels can be found <a target="_blank" href="https://blogs.technet.microsoft.com/windowsitpro/2017/07/27/waas-simplified-and-aligned/" rel="noopener">here</a>. The <strong>Release</strong> column either shows the date of the initial release for each version or it shows the approximate release date for future versions. <strong>Note</strong> that "End of Support" and "Extended Support" dates are subject to change.

<strong>Update 06.09.2018</strong>: With todays <a href="https://www.microsoft.com/en-us/microsoft-365/blog/2018/09/06/helping-customers-shift-to-a-modern-desktop/">announcement</a> servicing for Windows 10 has changed in a major way. The table above already includes the new servicing changes.

<u>Note:</u> Information in this article targets Enterprise and Education versions of Windows 10. Pro and Home versions are not considered.

For further information on the values mentioned in the table, please visit following sites:
<a target="_blank" href="https://technet.microsoft.com/en-us/windows/release-info" rel="noopener">Windows 10 release information</a>
<a target="_blank" href="https://support.microsoft.com/en-us/help/13853/windows-lifecycle-fact-sheet" rel="noopener">Windows lifecycle fact sheet</a>
<a target="_blank" href="https://docs.microsoft.com/en-us/windows-insider/flight-hub/" rel="noopener">Windows 10 Insider previews (Flight Hub)</a>
<a href="https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/versions-and-dependencies">Windows 10 .NET runtime versions</a>

Last modified on October 09, 2018]]></content:encoded>
    </item>
    <item>
      <title>Disassemble Powershell CMDLets</title>
      <link>https://docs.microsoft.com/archive/blogs/hewagen/disassemble-powershell-cmdlets</link>
      <pubDate>Thu, 14 Dec 2017 19:11:32 GMT</pubDate>
      <dc:creator><![CDATA[Helmut Wagensonner (MS)]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/hewagen/?p=26</guid>
      <description><![CDATA[Ever wondered how the Microsoft guys code their powershell CMDLets? Ever wanted to take a peek at...]]></description>
      <content:encoded><![CDATA[Ever wondered how the Microsoft guys code their powershell CMDLets? Ever wanted to take a peek at the implementation of a Powershell command? <em><a href="https://en.wikipedia.org/wiki/Red_pill_and_blue_pill" rel="noopener" target="_blank">"Then take the red pill, stay in wonderland and I show you how deep the rabbit hole goes. Remember: all I'm offering is the truth. Nothing more."</a></em>

Everything starts with the Get-Command CMDlet. Using Get-Command you can figure out a lot of properties of the command you want to look behind. The most important thing we need to know about a command is its type. The way to get to the script code is different for each command type. There are a lot of <a href="https://docs.microsoft.com/en-us/dotnet/api/system.management.automation.commandtypes?view=powershellsdk-1.1.0">command types</a> but most Powershell commands are of type "CMDLet" or "Function". Another command type is "Alias". But this is just a refenrence to a "CMDLet" or "Function". So let's focus on these two for now.

For this walkthrough I picked the "GC" (Get-Content) command as example for a CMDLet and "Get-WindowsUpdateLog" as an example for a Function.
<br>
<u>The CMDLet inside a .NET binary</u>

Let's start to x-ray "Get-Content" by opening a Powershell window (doesn't need to be elevated) and typing the following command:

<code>Get-Command gc | fl *</code>

<img src="https://msdnshared.blob.core.windows.net/media/2017/12/139.png" alt="" width="858" height="482" class="alignnone size-full wp-image-35" />

Using the short form "GC" with Get-Command, like we just did, shows "Alias" as CommandType property. To figure out the full name of the command, take a look at the "ResolvedCommandName" property and repeat Get-Command with its value. Using the long form shows the real command type, in this case a CMDLet.

<code>Get-Command Get-Content | fl *</code>

<img src="https://msdnshared.blob.core.windows.net/media/2017/12/227.png" alt="" width="859" height="732" class="alignnone size-full wp-image-45" />

The DLL property of the output indicates where the implementation of this CMDLet can be found. Since this is a binary format (.DLL), we need a disassembler to continue. There are a lot of tools to disassemble a dotNet binary. I use <a href="https://www.ilspy.net">ILSpy</a>. It's fast and can be installed as a portable app (no installation necessary).

So let's open the file from the DLL property (Microsoft.PowerShell.Commands.Management.dll) in ILSpy. Most times the command implementation is found in the "Microsoft.PowerShell.Commands" namespace.

<img src="https://msdnshared.blob.core.windows.net/media/2017/12/318.png" alt="" width="1064" height="639" class="alignnone size-full wp-image-55" />

From now on a little knowledge about .NET programming is necessary but as a rough indication we can search for methods like "ProcessRecord" or "BeginProcessing" to get a starting point.

<img src="https://msdnshared.blob.core.windows.net/media/2017/12/415.png" alt="" width="1310" height="740" class="alignnone size-full wp-image-56" />
<br>
<u>The Function way</u>

It's different when we need to get the source code for a command implemented as a function. As mentioned at the beginning, we use the "Get-WindowsUpdateLog" as an example here. So let's have a look at its members.

<code>Get-Command Get-WindowsUpdateLog | fl *</code>

<img src="https://msdnshared.blob.core.windows.net/media/2017/12/514.png" alt="" width="860" height="550" class="alignnone size-full wp-image-65" />

The source code of the function itself can be found in the "Definition" property. So it can easily be displayed using the command:

<code>Get-Command Get-WindowsupdateLog | select -ExpandProperty Definition</code>

<img src="https://msdnshared.blob.core.windows.net/media/2017/12/611.png" alt="" width="859" height="732" class="alignnone size-full wp-image-75" />

However, in many cases, the function is using code parts or other functions from its parent module. To view the complete source code, we need to open the whole module in a text editor.

First, let's find the parent module:

<code>Get-Command Get-WindowsUpdateLog | select -ExpandProperty ModuleName</code>

<img src="https://msdnshared.blob.core.windows.net/media/2017/12/77.png" alt="" width="859" height="122" class="alignnone size-full wp-image-85" />

It's part of the "WindowsUpdate" module. But where to find it? Well, that's easy:

<code>Get-Module -Name WindowsUpdate | select -ExpandProperty Path</code>

<img src="https://msdnshared.blob.core.windows.net/media/2017/12/86.png" alt="" width="859" height="94" class="alignnone size-full wp-image-95" />

This displays the path to the module definition file (*.psd1) or to the compiled module (*.dll) The compiled module can be opened with your favorite decompiler. In this example we have module definition file. So let's open the PSD1 in a text editor.

<img src="https://msdnshared.blob.core.windows.net/media/2017/12/97.png" alt="" width="1096" height="690" class="alignnone size-full wp-image-97" />

Find the line "ModuleList" or "NestedModules". In both of them you can figure out the path to the module files (*.psm1). The module files normally reside in the same directory. One of those files contains the implementation of the function, found in the definition property of the Get-Command output. In our case it's easy because this psd1 only contains one module. So let's go and open the PSM1 file in our favorite text editor.

<img src="https://msdnshared.blob.core.windows.net/media/2017/12/1010.png" alt="" width="1096" height="690" class="alignnone size-full wp-image-105" />

Here we have the complete implementation of our function.

You may have noticed, that I used the terms "normally, most times..." quite often in this tutorial. This is because there are different ways for implementation of CMDLets. Reversing other commands could slightly differ to the steps mentioned above. Anyway it's starting point.
]]></content:encoded>
    </item>
  </channel>
</rss>