<div class="content" name="RpcWaitForSessionState" uuid="637ac10c-6570-4603-8022-3c34ea2ea73a"><p>The RpcWaitForSessionState method blocks until the state of
the specified session running on a <span><a href="c41d3367-04c9-4c93-babf-9b5de834eb29#gt_b416f72e-cf04-4d80-bf93-f5753f3b0998" data-linktype="relative-path">terminal server</a></span>
changes to the desired state. The caller MUST have WINSTATION_QUERY permission
for the session. The method checks whether the caller has WINSTATION_QUERY
permission (section <span><a href="4507e852-be3d-45b6-bc47-8ca0b552c94d" data-linktype="relative-path">3.1.1</a></span>) by setting
it as the Access Request mask, and fails if the caller does not have the
permission. </p><dl>
<dd>
<div><pre> HRESULT RpcWaitForSessionState(
   [in] handle_t hBinding,
   [in] LONG SessionId,
   [in] LONG State,
   [in] ULONG Timeout
 );
</pre></div>
</dd></dl><p><b>hBinding: </b> The <span><a href="c41d3367-04c9-4c93-babf-9b5de834eb29#gt_8a7f6700-8311-45bc-af10-82e10accd331" data-linktype="relative-path">RPC</a></span> binding <span><a href="c41d3367-04c9-4c93-babf-9b5de834eb29#gt_5044babb-08e3-4bb9-bc12-fe8f542b05ee" data-linktype="relative-path">handle</a></span>.
For more information, see <span><a href="https://go.microsoft.com/fwlink/?LinkId=93771" data-linktype="external">[MSDN-RPCBIND]</a></span>.</p><p><b>SessionId: </b> The ID of the session for which to
await state change. This MUST NOT be the session ID of any of the <span><a href="c41d3367-04c9-4c93-babf-9b5de834eb29#gt_1e5aa0c2-4617-4d7a-969e-a7091c415c8d" data-linktype="relative-path">listener</a></span>
sessions.</p><p><b>State: </b> The desired state of the session, as
specified in <span><a href="b619d8aa-4e8a-4716-954e-a4d596ed37f8" data-linktype="relative-path">WINSTATIONSTATECLASS (section 2.2.1.9)</a></span>
with the exception of State_Idle and State_Listen, for which to wait. The call
will return when the session changes to this state.</p><p><b>Timeout: </b> Maximum time, in milliseconds, to
wait for the call to return.</p><p><b>Return Values: </b> The method MUST return S_OK
(0x00000000) on success; otherwise, it MUST return an implementation-specific
negative value.</p><dl>
<dd>
<table><thead>
  <tr>
   <th>
   <p>Return value/code</p>
   </th>
   <th>
   <p>Description</p>
   </th>
  </tr>
 </thead><tbody><tr>
  <td>0x00000000 S_OK</td>
  <td>Successful completion.</td>
 </tr></tbody></table>
</dd></dl><p> </p></div>