<div class="content" name="Attach" uuid="12172d46-0a26-41df-a5b4-3236a8ef9d0c"><p>The Attach method creates an operating system disk device
for a <a href="8eef5d42-22d7-4302-aed9-12face91505a#gt_1fbc35d5-bcf5-4ce7-9449-4197a1671440" data-linktype="relative-path">virtual disk</a>.</p><dl>
<dd>
<div><pre> HRESULT Attach(
   [in, unique] LPWSTR pStringSecurityDescriptor,
   [in] ATTACH_VIRTUAL_DISK_FLAG Flags,
   [in] ULONG ProviderSpecificFlags,
   [in] ULONG TimeoutInMs,
   [out] IVdsAsync** ppAsync
 );
</pre></div>
</dd></dl><p><b>pStringSecurityDescriptor: </b>A NULL-terminated
wide-character string containing the security descriptor to be applied to the
virtual disk.<a id="Appendix_A_Target_140"></a><a aria-label="Product behavior note 140" href="6b2552ee-ba27-409f-99a8-18841573327a#Appendix_A_140" data-linktype="relative-path">&lt;140&gt;</a> If this parameter is NULL,
the security descriptor in the caller&#39;s access token MUST be used.</p><p><b>Flags: </b>A bitmask of <a href="32a46f9f-66be-44e8-951f-563368084546" data-linktype="relative-path">ATTACH_VIRTUAL_DISK_FLAG (section 2.2.2.20.1.1)</a>
enumeration values specifying virtual disk attaching options.</p><p><b>ProviderSpecificFlags: </b>A bitmask of flags that
are specific to the type of virtual disk that is being surfaced. These flags
are provider-specific.<a id="Appendix_A_Target_141"></a><a aria-label="Product behavior note 141" href="6b2552ee-ba27-409f-99a8-18841573327a#Appendix_A_141" data-linktype="relative-path">&lt;141&gt;</a> </p><p><b>TimeoutInMs: </b>The length of time, in
milliseconds, before this method MAY<a id="Appendix_A_Target_142"></a><a aria-label="Product behavior note 142" href="6b2552ee-ba27-409f-99a8-18841573327a#Appendix_A_142" data-linktype="relative-path">&lt;142&gt;</a> return
after waiting for the virtual disk to be surfaced completely. If this parameter
is zero, the method returns immediately without waiting for the <a href="8eef5d42-22d7-4302-aed9-12face91505a#gt_c4133b2a-a990-4042-ba44-7fda3090f118" data-linktype="relative-path">disk</a> to be surfaced. If
this parameter is INFINITE, the method does not return until the surfacing
operation is complete. If this parameter is set to a value other than zero or
INFINITE and the time-out value is reached, the method guarantees that the disk
is not surfaced after the operation is complete.</p><p><b>ppAsync: </b>A pointer to an <a href="97ea9c0f-5c8a-43e9-a9ee-deda29e2a09e" data-linktype="relative-path">IVdsAsync (section 3.1.3.1)</a>
<a href="8eef5d42-22d7-4302-aed9-12face91505a#gt_95913fbd-3262-47ae-b5eb-18e6806824b9" data-linktype="relative-path">interface</a> that, if the
operation is successfully completed, receives the IVdsAsync interface to
monitor and control this operation. Callers MUST release the interface when
they are done with it.</p><p><b>Return Values: </b>This method MUST return zero to
indicate success, or return an implementation-specific nonzero error code to
indicate failure.</p><p>When the server receives this message, it MUST validate the
following parameters:</p><ul><li><p><span><span> 
</span></span>Verify that <i>ppAsync</i> is not NULL.</p>
</li></ul><p>The server MUST perform the following:</p><ul><li><p><span><span> 
</span></span>Create a new async object implementing the IVdsAsync interface
with an output type of VDS_ASYNCOUT_ATTACH_VDISK and set the pointer <i>ppAsync</i>
to the interface.</p>
</li><li><p><span><span> 
</span></span>Return an <a href="../ms-dtyp/a9046ed2-bfb2-4d56-a719-2824afce59ac" data-linktype="relative-path"><span>HRESULT</span></a> indicating
failure or success. Any errors encountered up through this point in processing
the operation are returned in this HRESULT.</p>
</li></ul><p>The server MUST then perform the following in sequence.
Errors generated in this sequence of steps are returned in the pHrResult
parameter to the IVdsAsync::Wait or IVdsAsyncQueryStatus methods.</p><ul><li><p><span><span> 
</span></span>Pass the input parameters to the operating system to attach the
virtual disk.</p>
</li><li><p><span><span> 
</span></span>Set the return code in the async object to an HRESULT indicating
failure or success of the operating system. If the task completed successfully,
set the percentage-completed value in the async object to 100.</p>
</li><li><p><span><span> 
</span></span>Set the signal state in the async object to TRUE.</p>
</li></ul><p>At any point in the preceding sequence, before the
percentage-completed value in the async object is 100, the server MUST update
the percentage-completed value if forward progress is made during the compact
operation.</p></div>