<div class="content"><p>The RQueryServiceStatus method returns the current status of
the specified service.</p><dl>
<dd>
<div><pre> DWORD RQueryServiceStatus(
   [in] SC_RPC_HANDLE hService,
   [out] LPSERVICE_STATUS lpServiceStatus
 );
</pre></div>
</dd></dl><p><b>hService: </b>An <a href="b5f0a0a8-887c-4097-af1c-71ef9f214ce4" data-linktype="relative-path">SC_RPC_HANDLE</a> (section
2.2.4) data type that defines the handle to the <a href="4f66d32e-2f4f-4482-998e-e5ccbb445223#gt_1fbb7936-8437-4e3d-b62f-47df3be07721" data-linktype="relative-path">service record</a> that MUST
have been created previously using one of the open methods specified in section
<a href="0d7a7011-9f41-470d-ad52-8535b47ac282" data-linktype="relative-path">3.1.4</a>. The
SERVICE_QUERY_STATUS access right MUST have been granted to the caller when the
RPC context handle was created.</p><p><b>lpServiceStatus: </b>Pointer to a <a href="4e91ff36-ab5f-49ed-a43d-a308e72b0b3c" data-linktype="relative-path">SERVICE_STATUS (section 2.2.47)</a>
structure that contains the status information for the service.</p><p><b>Return Values: </b>The method returns 0x00000000
(ERROR_SUCCESS) on success; otherwise, it returns one of the following error
codes.</p><dl>
<dd>
<table><thead>
  <tr>
   <th>
   <p>Return value/code</p>
   </th>
   <th>
   <p>Description</p>
   </th>
  </tr>
 </thead><tbody><tr>
  <td>
  <p>5</p>
  <p>ERROR_ACCESS_DENIED</p>
  </td>
  <td>
  <p>The SERVICE_QUERY_STATUS access right had not been granted
  to the caller when the RPC context handle was created.</p>
  </td>
 </tr><tr>
  <td>
  <p>6</p>
  <p>ERROR_INVALID_HANDLE</p>
  </td>
  <td>
  <p>The handle is no longer valid.</p>
  </td>
 </tr><tr>
  <td>
  <p>3</p>
  <p>ERROR_PATH_NOT_FOUND</p>
  </td>
  <td>
  <p>The ImagePath of the service record identified by the <i>hService</i>
  parameter does not exist.</p>
  </td>
 </tr><tr>
  <td>
  <p>1115</p>
  <p>ERROR_SHUTDOWN_IN_PROGRESS</p>
  </td>
  <td>
  <p>The system is shutting down.</p>
  </td>
 </tr></tbody></table>
</dd></dl><p>If the type of the service record is SERVICE_KERNEL_DRIVER
or SERVICE_FILESYSTEM_DRIVER, the <a href="4f66d32e-2f4f-4482-998e-e5ccbb445223#gt_afc3f782-a908-486d-9c05-8a054cd9cc84" data-linktype="relative-path">SCM</a> queries the current
status of the driver from the operating system and set the
ServiceStatus.dwCurrentState of the service record to SERVICE_RUNNING if driver
is loaded and to SERVICE_STOPPED if it is not.</p><p>In response to this request from the client, for a
successful operation, the server MUST set the ServiceStatus from the service
record identified by the <i>hService</i> parameter of the request in the <i>lpServiceStatus</i>
parameter. </p><p>If no attempts to start the service for the service record
identified by the <i>hService</i> parameter have been made since the last boot,
the server MUST set the dwWin32ExitCode member of the <i>lpServiceStatus</i>
parameter to 1077 ERROR_SERVICE_NEVER_STARTED.</p></div>