<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>words &#187; Windows</title>
	<atom:link href="http://www.curlybrace.com/words/category/technology/windows-technology/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.curlybrace.com/words</link>
	<description>by Jeff Fitzsimons</description>
	<lastBuildDate>Tue, 20 Dec 2011 10:21:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>What Exactly Are ATL&#8217;s BEGIN_COM_MAP, END_COM_MAP, and COM_INTERFACE_ENTRY Macros?</title>
		<link>http://www.curlybrace.com/words/2011/12/20/what-exactly-are-atls-begin_com_map-end_com_map-and-com_interface_entry/</link>
		<comments>http://www.curlybrace.com/words/2011/12/20/what-exactly-are-atls-begin_com_map-end_com_map-and-com_interface_entry/#comments</comments>
		<pubDate>Tue, 20 Dec 2011 10:20:44 +0000</pubDate>
		<dc:creator>Jeff Fitzsimons</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[COM]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.curlybrace.com/words/?p=1959</guid>
		<description><![CDATA[There are many places where ATL&#8217;s COM_MAP macros are documented, but I haven&#8217;t seen it plainly stated what they actually mean. Simply put, BEGIN_COM_MAP implements _InternalQueryInterface. COM_INTERFACE_ENTRY indicates that your class supports the specified interface. END_COM_MAP finishes the _InternalQueryInterface implementation. &#8230; <a href="http://www.curlybrace.com/words/2011/12/20/what-exactly-are-atls-begin_com_map-end_com_map-and-com_interface_entry/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>There are many places where ATL&#8217;s COM_MAP macros are documented, but I haven&#8217;t seen it plainly stated what they actually mean.</p>
<p>Simply put, BEGIN_COM_MAP implements _InternalQueryInterface.  COM_INTERFACE_ENTRY indicates that your class supports the specified interface.  END_COM_MAP finishes the _InternalQueryInterface implementation.</p>
<blockquote><p>Note:  A QueryInterface implementation which calls this _InternalQueryInterface method must either be hand-coded, <a href="http://msdn.microsoft.com/en-us/library/c43h4867(v=VS.100).aspx">or supplied by CComObject, CComAggObject, etc</a>.</p></blockquote>
<p>For example:</p>
<blockquote><pre>
class MyClass :
    public CComObjectRoot,
    public ISomeInterface
{
public:
    BEGIN_COM_MAP(MyClass)
        COM_INTERFACE_ENTRY(ISomeInterface)
    END_COM_MAP()
};

CComClass<MyClass> myInstance = new CComClass<MyCLass>;
</pre>
</blockquote>
<p>The COM_INTERFACE_ENTRY line indicates that MyClass implements ISomeInterface.  If QueryInterface is called to requests an ISomeInterface pointer, the call will succeed.  Without the COM_INTERFACE_ENTRY line, the QueryInterface call would fail.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.curlybrace.com/words/2011/12/20/what-exactly-are-atls-begin_com_map-end_com_map-and-com_interface_entry/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Enabling Wake-On-LAN on a Toshiba Satellite A505</title>
		<link>http://www.curlybrace.com/words/2011/06/03/enabling-wake-on-lan-on-a-toshiba-satellite-a505/</link>
		<comments>http://www.curlybrace.com/words/2011/06/03/enabling-wake-on-lan-on-a-toshiba-satellite-a505/#comments</comments>
		<pubDate>Fri, 03 Jun 2011 22:58:30 +0000</pubDate>
		<dc:creator>Jeff Fitzsimons</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.curlybrace.com/words/?p=1725</guid>
		<description><![CDATA[This post describes how I fixed my Wake-On-LAN problem using the powercfg tool. My Toshiba Satellite A505-S6986 wouldn&#8217;t respond to magic packets sent over the network. Before using powercfg, I first checked the following: Wake-On-LAN was enabled in the BIOS. &#8230; <a href="http://www.curlybrace.com/words/2011/06/03/enabling-wake-on-lan-on-a-toshiba-satellite-a505/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This post describes how I fixed my Wake-On-LAN problem using the <tt>powercfg</tt> tool.  My Toshiba Satellite A505-S6986 wouldn&#8217;t respond to <a href="http://en.wikipedia.org/wiki/Magic_Packet#Magic_packet">magic packets</a> sent over the network.</p>
<p>Before using <tt>powercfg</tt>, I first checked the following:</p>
<ol>
<li />Wake-On-LAN was enabled in the BIOS.
<li /><img src="http://www.curlybrace.com/words/wp-content/uploads/2011/05/Realtek_AdvancedTab.png" alt="" title="Realtek_AdvancedTab" width="332" height="369" class="alignright size-full wp-image-1740" />All settings related to Wake-On-LAN were enabled in the adapter&#8217;s Advanced properties tab:
<ul>
<li />Shutdown Wake-On-Lan
<li />Wake on Magic Packet
<li />Wake on pattern match<br clear="all">
</ul>
<li /><img src="http://www.curlybrace.com/words/wp-content/uploads/2011/05/Realtek_PowerManagementTab.png" alt="" title="Realtek_PowerManagementTab" width="332" height="369" class="alignright size-full wp-image-1741" />All wake-related settings were checked on the Power Management properties tab:
<ul>
<li />Allow this device to wake computer
<li />Only allow a magic packet to wake the computer<br clear="all">
</ul>
</ol>
<p>Even with these settings configured properly, my laptop still wouldn&#8217;t respond to magic packets.<br />
First, I opened a command prompt <b>as administrator</b>.  A regular user doesn&#8217;t have the access rights to change power options.</p>
<p>Then, I checked to see if the LAN adapter is in the list of devices which can wake Windows:</p>
<pre class="DOS">C:\Windows\system32>powercfg -devicequery wake_armed
HID Keyboard Device (002)
HID-compliant mouse (001)
Logitech USB Wheel Mouse (004)</pre>
<p>The Ethernet adapter isn&#8217;t in there, so I looked at the list of wake-programmable devices in order to find out the name of my LAN adapter:</p>
<pre class="DOS">C:\Windows\system32>powercfg -devicequery wake_programmable
HID-compliant device
Realtek PCIe FE Family Controller            <=== LAN adapter
HID Keyboard Device (002)
TOSHIBA Software Modem
HID-compliant mouse (001)
HID-compliant consumer control device (001)
Logitech USB Wheel Mouse (004)</pre>
<p>Finally, I enabled wake for my Ethernet device, using the name "Realtex PCIe FE Family Controller":</p>
<pre class="DOS">C:\Windows\system32>powercfg -deviceenablewake "Realtek PCIe FE Family Controller"</pre>
<p>(if you see an error like, "<tt>Invalid Parameters -- try "/?" for help</tt>," it most likely means that you mistyped the device name)</p>
<p>I am now able to wake my laptop from sleep and hibernate modes using the <a href="https://market.android.com/details?id=net.mafro.android.wakeonlan">Wake On Lan app</a> for my Android device.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.curlybrace.com/words/2011/06/03/enabling-wake-on-lan-on-a-toshiba-satellite-a505/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>iTunes COM SDK for Windows and Encrypted File System</title>
		<link>http://www.curlybrace.com/words/2011/04/04/itunes-com-sdk-for-windows-and-encrypted-file-system/</link>
		<comments>http://www.curlybrace.com/words/2011/04/04/itunes-com-sdk-for-windows-and-encrypted-file-system/#comments</comments>
		<pubDate>Mon, 04 Apr 2011 22:45:57 +0000</pubDate>
		<dc:creator>Jeff Fitzsimons</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.curlybrace.com/words/?p=1664</guid>
		<description><![CDATA[The &#8220;iTunes COM SDK for Windows&#8221; archive from the Apple Developer Center contains files which are marked as encrypted. Shortly after extracting the files to my libraries folder, I was surprised to receive a popup dialog from Windows 7, &#8220;Encrypting &#8230; <a href="http://www.curlybrace.com/words/2011/04/04/itunes-com-sdk-for-windows-and-encrypted-file-system/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The &#8220;iTunes COM SDK for Windows&#8221; archive from the Apple Developer Center contains files which are marked as encrypted.  Shortly after extracting the files to my libraries folder, I was surprised to receive a popup dialog from Windows 7, &#8220;Encrypting File System,&#8221; which prompted me to back up my encryption certificate and key:</p>
<blockquote><p><img src="http://www.curlybrace.com/words/wp-content/uploads/2011/04/Encrypting-FileSystem_Dialog.png" alt="Windows 7 &quot;Encrypting File System&quot; dialog" title="Encrypting FileSystem_Dialog" width="386" height="309" /></p></blockquote>
<p>I used <tt>CIPHER.EXE</tt> to verify that the only encrypted contents on the volume were those of the Apple download:</p>
<blockquote><pre class="DOS">C:\lib>cipher /u /n

Encrypted File(s) on your system:

C:\lib\24460_itunescomwindowssdk\iTunesCOMWindowsSDK\.DS_Store
C:\lib\24460_itunescomwindowssdk\iTunesCOMWindowsSDK\iTunesCOM.chm
C:\lib\24460_itunescomwindowssdk\iTunesCOMWindowsSDK\iTunesCOMInterface.h
C:\lib\24460_itunescomwindowssdk\iTunesCOMWindowsSDK\iTunesCOMInterface_i.c
C:\lib\24460_itunescomwindowssdk\iTunesCOMWindowsSDK\LicenseAgreement.rtf
C:\lib\24460_itunescomwindowssdk\iTunesCOMWindowsSDK\ReadMe.rtf
C:\lib\24460_itunescomwindowssdk\iTunesCOMWindowsSDK\SampleScripts\.DS_Store
C:\lib\24460_itunescomwindowssdk\iTunesCOMWindowsSDK\SampleScripts\CreateAlbumPlaylists.js
C:\lib\24460_itunescomwindowssdk\iTunesCOMWindowsSDK\SampleScripts\RemoveDeadTracks.js
C:\lib\24460_itunescomwindowssdk\iTunesCOMWindowsSDK\SampleScripts\RemoveUserPlaylists.js
C:\lib\24460_itunescomwindowssdk\__MACOSX\._iTunesCOMWindowsSDK
C:\lib\24460_itunescomwindowssdk\__MACOSX\iTunesCOMWindowsSDK\._.DS_Store
C:\lib\24460_itunescomwindowssdk\__MACOSX\iTunesCOMWindowsSDK\._iTunesCOM.chm
C:\lib\24460_itunescomwindowssdk\__MACOSX\iTunesCOMWindowsSDK\._iTunesCOMInterface.h
C:\lib\24460_itunescomwindowssdk\__MACOSX\iTunesCOMWindowsSDK\._iTunesCOMInterface_i.c
C:\lib\24460_itunescomwindowssdk\__MACOSX\iTunesCOMWindowsSDK\._LicenseAgreement.rtf
C:\lib\24460_itunescomwindowssdk\__MACOSX\iTunesCOMWindowsSDK\._ReadMe.rtf
C:\lib\24460_itunescomwindowssdk\__MACOSX\iTunesCOMWindowsSDK\._SampleScripts
C:\lib\24460_itunescomwindowssdk\__MACOSX\iTunesCOMWindowsSDK\SampleScripts\._.DS_Store
C:\lib\24460_itunescomwindowssdk\__MACOSX\iTunesCOMWindowsSDK\SampleScripts\._CreateAlbumPlaylists.js
C:\lib\24460_itunescomwindowssdk\__MACOSX\iTunesCOMWindowsSDK\SampleScripts\._RemoveDeadTracks.js
C:\lib\24460_itunescomwindowssdk\__MACOSX\iTunesCOMWindowsSDK\SampleScripts\._RemoveUserPlaylists.js</pre>
</blockquote>
<p>To fix this, I opened the properties for the <tt>iTunesCOMWindowsSDK</tt> folder, selected the General tab, clicked Advanced, and unselected &#8220;Encrypt contents to secure data&#8221;:</p>
<blockquote><p><img src="http://www.curlybrace.com/words/wp-content/uploads/2011/04/iTunesCOMWindowsSDK_PropertiesGeneral.png" alt="" title="iTunesCOMWindowsSDK_PropertiesGeneral" width="302" height="390" /></p>
<p><img src="http://www.curlybrace.com/words/wp-content/uploads/2011/04/iTunesCOMWindowsSDK_PropertiesGeneralAdvanced.png" alt="" title="iTunesCOMWindowsSDK_PropertiesGeneralAdvanced" width="316" height="278" /></p>
<p><img src="http://www.curlybrace.com/words/wp-content/uploads/2011/04/iTunesCOMWindowsSDK_ApplyChanges.png" alt="" title="iTunesCOMWindowsSDK_ApplyChanges" width="322" height="203" /></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.curlybrace.com/words/2011/04/04/itunes-com-sdk-for-windows-and-encrypted-file-system/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Where is the iTunes SDK?</title>
		<link>http://www.curlybrace.com/words/2011/04/04/where-is-the-itunes-sdk/</link>
		<comments>http://www.curlybrace.com/words/2011/04/04/where-is-the-itunes-sdk/#comments</comments>
		<pubDate>Mon, 04 Apr 2011 22:35:45 +0000</pubDate>
		<dc:creator>Jeff Fitzsimons</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.curlybrace.com/words/?p=1666</guid>
		<description><![CDATA[The Apple iTunes SDK (&#8220;iTunes COM SDK for Windows&#8221;) is astonishingly difficult to find. It can be found on the]]></description>
			<content:encoded><![CDATA[<p>The Apple iTunes SDK (&#8220;iTunes COM SDK for Windows&#8221;) is astonishingly difficult to find.  It can be found on the <a href="http://connect.apple.com"</a>Dowloads &#038; ADC Program Assets (connect.apple.com)</a> page.  In the &#8220;Downloads&#8221; box on the right, click on &#8220;Developer Tools,&#8221; then search the page for &#8220;iTunes COM SDK for Windows.&#8221;</p>
<p>The irritating thing is that there seems to be no direct path from the Apple Developer&#8217;s Center to this &#8220;Downloads &#038; ADC Program Assets&#8221; page.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.curlybrace.com/words/2011/04/04/where-is-the-itunes-sdk/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>id3v2:  Command Line MP3 Tag Editor Compiled for Cygwin</title>
		<link>http://www.curlybrace.com/words/2011/03/09/id3v2-command-line-mp3-tag-editor-compiled-for-cygwin/</link>
		<comments>http://www.curlybrace.com/words/2011/03/09/id3v2-command-line-mp3-tag-editor-compiled-for-cygwin/#comments</comments>
		<pubDate>Thu, 10 Mar 2011 01:22:19 +0000</pubDate>
		<dc:creator>Jeff Fitzsimons</dc:creator>
				<category><![CDATA[Cygwin]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.curlybrace.com/words/?p=1627</guid>
		<description><![CDATA[id3v2 is a powerful command line tool for editing MP3 ID3 tags.  Getting it to compile on Windows under Cygwin, though, took a bit of effort. For the convenience of others, here is id3v2 0.1.12 compiled under Cygwin.  It depends &#8230; <a href="http://www.curlybrace.com/words/2011/03/09/id3v2-command-line-mp3-tag-editor-compiled-for-cygwin/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://id3v2.sourceforge.net/">id3v2</a> is a powerful command line tool for editing MP3 ID3 tags.  Getting it to compile on Windows under Cygwin, though, took a bit of effort.</p>
<p>For the convenience of others, <a href="http://www.curlybrace.com/words/wp-content/uploads/2011/03/id3v2.exe">here is id3v2 0.1.12 compiled under Cygwin</a>.  It depends upon Cygwin and Cygwin&#8217;s zlib package.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.curlybrace.com/words/2011/03/09/id3v2-command-line-mp3-tag-editor-compiled-for-cygwin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BluetoothAPIs.h Broken in Windows SDK</title>
		<link>http://www.curlybrace.com/words/2011/01/17/bluetoothapis-h-broken-in-windows-sdk/</link>
		<comments>http://www.curlybrace.com/words/2011/01/17/bluetoothapis-h-broken-in-windows-sdk/#comments</comments>
		<pubDate>Mon, 17 Jan 2011 08:54:21 +0000</pubDate>
		<dc:creator>Jeff Fitzsimons</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Win32]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.curlybrace.com/words/?p=1551</guid>
		<description><![CDATA[Summary The Microsoft Windows SDK versions 7.0 and 7.1 appear to have broken BluetoothAPIs.h header files. Details So far, I have uncovered two types of errors in this header file: The use of #pragma deprecate instead of #pragma deprecated, causing &#8230; <a href="http://www.curlybrace.com/words/2011/01/17/bluetoothapis-h-broken-in-windows-sdk/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h2>Summary</h2>
<p>The Microsoft Windows SDK versions 7.0 and 7.1 appear to have broken BluetoothAPIs.h header files.</p>
<h2>Details</h2>
<p>So far, I have uncovered two types of errors in this header file:
<ul>
<li />The use of <tt>#pragma deprecate</tt> instead of <tt>#pragma deprecated</tt>, causing compiler warnings.
<li />Several callback function pointer type definitions omit the <tt>CALLBACK</tt> (<a href="http://msdn.microsoft.com/en-us/library/zxk0tw93(v=vs.80).aspx"><tt>__stdcall</tt></a>) calling convention, causing a crash.
</ul>
<p>The first error simply results in compiler warnings.</p>
<blockquote><pre>warning C4068: unknown pragma</pre>
</blockquote>
<p>The second type of error results in dereferencing of an invalid memory location when using <tt>BluetoothRegisterForAuthenticationEx</tt> and <tt>BluetoothAuthenticateDeviceEx</tt>.  This is because the standard calling convention (<a href="http://msdn.microsoft.com/en-us/library/zkwh89ks(v=vs.80).aspx"><tt>__cdecl</tt></a>) assumes that the caller will clean up the stack.  Since the caller in this case is assuming that the callback function minded its own stack, it immediately pops <tt>ESI</tt>, placing zero into the register:</p>
<blockquote><pre>5EBCFFE2  mov         ecx,dword ptr [ebp-4]
5EBCFFE5  pop         esi
5EBCFFE6  xor         ecx,ebp
5EBCFFE8  pop         ebx
5EBCFFE9  call        @__security_check_cookie@4 (5EBDBBBBh)</pre>
</blockquote>
<p>Later, ntdll.dll dereferences memory at <tt>ESI + 4</tt>, triggering an access violation:</p>
<blockquote><pre>774A8301  test        byte ptr [esi+4],4</pre>
</blockquote>
<blockquote><p>&#8220;Unhandled exception at 0x774a8301 (ntdll.dll) in [Application]: 0xC0000005: Access violation reading location 0&#215;00000004.</p></blockquote>
<h2>Solution</h2>
<p>To the compiler warnings, I replaced all instances of </p>
<blockquote><p><tt>#pragma deprecate</tt></p></blockquote>
<p>with</p>
<blockquote><p><tt>#pragma deprecate<b>d</b></tt></p></blockquote>
<p>To fix the crash bug, I added the <tt>CALLBACK</tt> calling convention keyword to <tt>PFN_AUTHENTICATION_CALLBACK</tt> and <tt>PFN_AUTHENTICATION_CALLBACK_EX</tt>.  They now appear as follows:</p>
<blockquote><p><tt>typedef BOOL (<b>CALLBACK</b> *PFN_AUTHENTICATION_CALLBACK)(LPVOID pvParam, PBLUETOOTH_DEVICE_INFO pDevice);</tt></p></blockquote>
<blockquote><p><tt>typedef BOOL (<b>CALLBACK</b> *PFN_AUTHENTICATION_CALLBACK_EX)(__in_opt LPVOID pvParam, __in PBLUETOOTH_AUTHENTICATION_CALLBACK_PARAMS pAuthCallbackParams);</tt></p></blockquote>
<p>Interestingly, the function pointer type definitions for the attribute-enumeration and device-selection callbacks (<tt>PFN_BLUETOOTH_ENUM_ATTRIBUTES_CALLBACK</tt> and <tt>PFN_DEVICE_CALLBACK</tt>, respectively) are defined correctly, using <tt>CALLBACK</tt> or <tt>WINAPI</tt>.  I suspect that the inconsistency is because someone at Microsoft was using the <tt>/Gz</tt> compiler switch, making <tt>__stdcall</tt> the default calling convention.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.curlybrace.com/words/2011/01/17/bluetoothapis-h-broken-in-windows-sdk/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Alternate Data Streams (Metadata) on Files in NTFS</title>
		<link>http://www.curlybrace.com/words/2011/01/01/alternate-data-streams/</link>
		<comments>http://www.curlybrace.com/words/2011/01/01/alternate-data-streams/#comments</comments>
		<pubDate>Sun, 02 Jan 2011 07:51:50 +0000</pubDate>
		<dc:creator>Jeff Fitzsimons</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.curlybrace.com/words/?p=1120</guid>
		<description><![CDATA[Introduction Alternate Data Streams (ADS) allow arbitrary metadata to be associated with files and directories on Windows NTFS. Alternate data streams are the Windows implementation of forks. The apparent size of the file will be unchanged, and most applications and &#8230; <a href="http://www.curlybrace.com/words/2011/01/01/alternate-data-streams/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h2>Introduction</h2>
<p>Alternate Data Streams (ADS) allow arbitrary metadata to be associated with files and directories on Windows NTFS.  Alternate data streams are the Windows implementation of <a href="http://en.wikipedia.org/wiki/Fork_%28filesystem%29">forks</a>.  The apparent size of the file will be unchanged, and most applications and users are unaware of their existence.  If a file is moved, any alternate data stream will move along with it, as long as the destination is on an NTFS drive.</p>
<p>The command line can access alternate data streams using redirection operators.  Streams are specified on the command line as <i>filename</i><b>:</b><i>stream name</i>.</p>
<h3>Creating an Alternate Data Stream</h3>
<p>As an example, a string is written into an ADS named <tt>hidden</tt>, which is associated with file <tt>test.txt</tt>:</p>
<blockquote><pre class="DOS">C:\test>echo Hidden text > test.txt:hidden</pre>
</blockquote>
<p>The file appears to be empty, though as detailed below, the metadata is intact and associated with the file:</p>
<blockquote><pre class="DOS">C:\test>dir test.txt

06/24/2010  01:33 PM                 0 test.txt</pre>
</blockquote>
<h3>Viewing an Alternate Data Stream</h3>
<p>The metadata can be viewed by redirecting from it to <tt>more</tt>:</p>
<blockquote><pre class="DOS">C:\test>more < test.txt:hidden
Hidden text</pre>
</blockquote>
<p>The name and content of the ADS can be anything (see 'Details' below for restrictions):</p>
<blockquote><pre class="DOS">C:\test>echo Arbitrary string > test.txt:arbitraryName

C:\test>more < test.txt:arbitraryName
Arbitrary string</pre>
</blockquote>
<h3>Listing Files With Alternate Data Streams</h3>
<p>On Windows Vista and later, a list of alternate data streams can be obtained using <tt>DIR /R</tt>:</p>
<blockquote><pre class="DOS">C:\test>dir test.txt /R

06/24/2010  01:33 PM                 0 test.txt
                                    38 test.txt:arbitraryName:$DATA
                                    28 test.txt:hidden:$DATA</pre>
</blockquote>
<p>On earlier operating systems, the SysInternals utility <a href="http://technet.microsoft.com/en-us/sysinternals/bb897440">Streams</a> can be used:</p>
<blockquote><pre class="DOS">C:\test>c:\tools\SysInternals\streams.exe test.txt

Streams v1.56 - Enumerate alternate NTFS data streams
Copyright (C) 1999-2007 Mark Russinovich
Sysinternals - www.sysinternals.com

C:\test\test.txt:
   :arbitraryName:$DATA 38
          :hidden:$DATA 28</pre>
</blockquote>
<h3>Alternate Data Streams on Directories</h3>
<p>Metadata can be added to directories the same way it's added to files:</p>
<blockquote><pre class="DOS">C:\test>mkdir test2

C:\test>echo ADS on a directory > test2:someText

C:\test>dir /r

06/25/2010  11:27 PM    &lt;DIR&gt;          .
06/25/2010  11:27 PM    &lt;DIR&gt;          ..
06/25/2010  11:27 PM    &lt;DIR&gt;          test2
                                    42 test2:someText:$DATA

C:\test>more < test2:someText
ADS on a directory</pre>
</blockquote>
<h2>Details</h2>
<h3>Stream Naming</h3>
<p>To be more accurate, streams are specified as <i>filename</i><b>:</b><i>stream name</i><b>:</b><i>stream type</i>.  It appears that the only stream type accessible from the command line is $DATA, which is why it's optional.  All of the stream types are listed in the <a href="http://msdn.microsoft.com/en-us/library/aa362667%28v=VS.85%29.aspx">WIN32_STREAM_ID structure documentation</a>.  The default data stream is unnamed, so <i>filename</i>::$DATA will contain the file's data:</p>
<blockquote><pre class="DOS">C:\test>echo This is the file > file.txt

C:\test>echo This is the stream > file.txt:stream

C:\test>more < file.txt::$DATA
This is the file

C:\test>more < file.txt:stream:$DATA
This is the stream</pre>
</blockquote>
<p>Stream names are generally held to the same requirements as any filename.  One interesting difference is that stream names can contain characters whose integer representations are in the range from 1 through 31.  Refer to <a href="http://msdn.microsoft.com/en-us/library/aa365247%28v=VS.85%29.aspx">Naming Files, Paths, and Namespaces</a> (MSDN) for details.</p>
<p>Note that when using streams with files having a single letter name, the filename should be prefixed with a period and backslash.  The reason for this is Windows drive names.  For example, does "<tt>echo hello > c:test</tt>" refer to a stream named <tt>test</tt> on file <tt>c</tt>, or does it refer to a file <tt>test</tt> on drive <tt>c</tt>?</p>
<h3>Executing Streams</h3>
<p>As of Windows Vista, it is no longer possible to execute directly from an alternate data stream.  On Windows XP and earlier, the Start command was used, similar to <tt>start somefile.ext:hiddenExecutable</tt>.</p>
<h3>Editing with Notepad</h3>
<p>Notepad can be used to create and edit alternate data streams.  The File Open dialog doesn't recognize stream syntax, however, so the file must be created and opened using command line parameters.  Notepad will insist on appending <tt>.txt</tt> to the stream name.</p>
<h3>Programmatic Access</h3>
<p>Microsoft provides a <a href="http://support.microsoft.com/kb/105763">sample program</a> in C++, demonstrating how to open and write to an alternate data stream.</p>
<h2>Real-World Applications</h2>
<h3>Downloaded Executables</h3>
<p><a href="http://blogs.msdn.com/b/oldnewthing/archive/2007/08/27/4580767.aspx?PageIndex=4">Since Windows XP SP2</a>, when a file is downloaded from the Internet and executed (assuming a zone-aware browser), this warning is displayed:</p>
<blockquote><p><a href="http://www.curlybrace.com/words/wp-content/uploads/2010/06/UAC_Example_s.png"><img src="http://www.curlybrace.com/words/wp-content/uploads/2010/06/UAC_Example_s.png" alt="" title="UAC_Example_s" width="320" height="192" class="aligncenter size-full wp-image-1127" /></a></p></blockquote>
<p>Windows displays this warning because the web browser tagged the executable with a alternate data stream named <tt>Zone.Identifier</tt>:</p>
<blockquote><pre class="DOS">C:\test>dir /r setup.exe

06/25/2010  12:10 PM           680,467 setup.exe
                                    26 setup.exe:Zone.Identifier:$DATA</pre>
</blockquote>
<p>By redirecting this stream to <tt>more</tt>, we can see its contents:</p>
<blockquote><pre class="DOS">C:\test>more < setup.exe:Zone.Identifier
[ZoneTransfer]
ZoneId=3</pre>
</blockquote>
<p>The <a href="http://blogs.msdn.com/b/powershell/archive/2007/03/07/how-does-the-remotesigned-execution-policy-work.aspx">PowerShell blog</a> has more information on zone identifiers.</p>
<h3>Viruses</h3>
<p>The W2K.Stream virus <a href="http://www.symantec.com/security_response/writeup.jsp?docid=2000-121416-2928-99">used alternate data streams</a>.</p>
<h2>Additional Resources</h2>
<ul>
<li /><a href="http://msdn.microsoft.com/en-us/library/ms810604.aspx"><del>A Programmer's Perspective on NTFS 2000 Part 1: Stream and Hard Link</del></a> (MSDN, article removed)
<li /><a href="http://msdn.microsoft.com/en-us/library/ms810500.aspx"><del>A Programmer's Perspective on NTFS 2000 Part 2: Encryption, Sparseness, and Reparse Points</del></a> (MSDN, article removed)
<li /><a href="http://msdn.microsoft.com/en-us/library/aa364404%28v=VS.85%29.aspx">File Streams</a> (MSDN)
<li /><a href="http://www.codeproject.com/KB/shell/csadsdetectorarticle.aspx">Visual browsing of alternative data-streams in Windows Explorer</a> (CodeProject)
<li /><a href="http://www.alex-ionescu.com/NTFS%20Alternate%20Data%20Streams.pdf">NTFS Alternate Data Streams</a> (Alex Ionescu)
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.curlybrace.com/words/2011/01/01/alternate-data-streams/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Console and Cygwin Don&#8217;t Show All Files on 64-bit Windows</title>
		<link>http://www.curlybrace.com/words/2010/12/17/console-and-cygwin-dont-show-all-files-on-64-bit-windows/</link>
		<comments>http://www.curlybrace.com/words/2010/12/17/console-and-cygwin-dont-show-all-files-on-64-bit-windows/#comments</comments>
		<pubDate>Fri, 17 Dec 2010 18:50:54 +0000</pubDate>
		<dc:creator>Jeff Fitzsimons</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.curlybrace.com/words/?p=1522</guid>
		<description><![CDATA[Running Cygwin bash or Console under 64-bit versions of Windows, directory listings sometimes differ from results shown in Explorer or cmd.exe. For example, Defrag.exe is visible to the default command shell (CMD): C:\Windows\System32>dir Defr* 07/13/2009 05:39 PM 183,296 Defrag.exe 07/13/2009 &#8230; <a href="http://www.curlybrace.com/words/2010/12/17/console-and-cygwin-dont-show-all-files-on-64-bit-windows/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Running Cygwin bash or <a href="http://sourceforge.net/projects/console/">Console</a> under 64-bit versions of Windows, directory listings sometimes differ from results shown in Explorer or <tt>cmd.exe</tt>.  For example, <tt>Defrag.exe</tt> is visible to the default command shell (CMD):</p>
<blockquote><pre class="DOS">C:\Windows\System32>dir Defr*

07/13/2009  05:39 PM           183,296 Defrag.exe
07/13/2009  05:40 PM            16,384 defragproxy.dll
07/13/2009  05:40 PM           291,328 defragsvc.dll</pre>
</blockquote>
<p>The same listing under Cygwin bash yields no results:</p>
<blockquote><pre class="bash">$ cd /cygdrive/c/Windows/System32

$ ls Defra*
ls: cannot access Defra*: No such file or directory</pre>
</blockquote>
<p>In fact, on this system, Cygwin reports sees only 2,465 files in System32, while CMD sees 2,857 files.</p>
<p>This is because Cygwin bash and Console are 32-bit applications, and I&#8217;m running 64-bit Windows.  With filesystem virtualization on Windows, when a 32-bit process attempts to access <tt>%SYSTEMROOT%\System32</tt>, it is redirected to <tt>%SYSTEMROOT%\SYSWOW64</tt>.  Ironically named, <tt>System32</tt> contains 64-bit applications, while <tt>SYSWOW64</tt> contains 32-bit applications.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.curlybrace.com/words/2010/12/17/console-and-cygwin-dont-show-all-files-on-64-bit-windows/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Install Windows 7 from USB Thumb Drive</title>
		<link>http://www.curlybrace.com/words/2010/11/27/install-windows-7-from-usb-thumb-drive/</link>
		<comments>http://www.curlybrace.com/words/2010/11/27/install-windows-7-from-usb-thumb-drive/#comments</comments>
		<pubDate>Sun, 28 Nov 2010 04:31:36 +0000</pubDate>
		<dc:creator>Jeff Fitzsimons</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.curlybrace.com/words/?p=1398</guid>
		<description><![CDATA[The Windows 7 USB/DVD Download Tool can copy a Windows .ISO file to a USB thumb/pen drive.]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://wudt.codeplex.com/">Windows 7 USB/DVD Download Tool</a> can copy a Windows .ISO file to a USB thumb/pen drive.</p>
<blockquote><p><a href="http://wudt.codeplex.com/"><img src="http://www.curlybrace.com/words/wp-content/uploads/2010/11/Windows7DownloadTool_Copying.png" alt="" title="Windows7DownloadTool_Copying" width="480" height="253" class="alignleft size-full wp-image-1399" /></a></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.curlybrace.com/words/2010/11/27/install-windows-7-from-usb-thumb-drive/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows Vista/7 File System Virtualization</title>
		<link>http://www.curlybrace.com/words/2010/09/09/windows-vista7-file-system-virtualization/</link>
		<comments>http://www.curlybrace.com/words/2010/09/09/windows-vista7-file-system-virtualization/#comments</comments>
		<pubDate>Thu, 09 Sep 2010 19:58:57 +0000</pubDate>
		<dc:creator>Jeff Fitzsimons</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.curlybrace.com/words/?p=1352</guid>
		<description><![CDATA[Along with User Account Control, Windows Vista and Windows 7 use file system and registry virtualization to improve compatibility with applications which break Windows development security guidelines. If an application attempts to write to a disallowed location (such as the &#8230; <a href="http://www.curlybrace.com/words/2010/09/09/windows-vista7-file-system-virtualization/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Along with User Account Control, Windows Vista and Windows 7 use file system and registry virtualization to improve compatibility with applications which break Windows development security guidelines.  If an application attempts to write to a disallowed location (such as the root directory, or Program Files), the file is silently relocated under <tt>%localappdata%/VirtualStore</tt>.</p>
<p>So, if you&#8217;re running an older application and you can&#8217;t figure out where it stored its files (e.g. DVD Decrypter, as in my case), look under:</p>
<blockquote><p><tt>C:\Users\username\AppData\Local\VirtualStore</tt></p></blockquote>
<p><a href="http://msdn.microsoft.com/en-us/library/bb756960.aspx?ppud=4">This MSDN page</a> has an excellent summary of file and registry virtualization (search the page for &#8220;virtualization&#8221;).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.curlybrace.com/words/2010/09/09/windows-vista7-file-system-virtualization/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

