<div class="content" name="RQueryServiceStatus" uuid="cf94d915-b4e1-40e5-872b-a9cb3ad09b46"><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 <span><a href="b5f0a0a8-887c-4097-af1c-71ef9f214ce4" data-linktype="relative-path">SC_RPC_HANDLE</a></span>
(section 2.2.4) data type that defines the handle to the <span><a href="4f66d32e-2f4f-4482-998e-e5ccbb445223#gt_1fbb7936-8437-4e3d-b62f-47df3be07721" data-linktype="relative-path">service
record</a></span> that MUST have been created previously using one of the open
methods specified in section <span><a href="0d7a7011-9f41-470d-ad52-8535b47ac282" data-linktype="relative-path">3.1.4</a></span>. 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 <span><a href="4e91ff36-ab5f-49ed-a43d-a308e72b0b3c" data-linktype="relative-path">SERVICE_STATUS (section 2.2.47)</a></span>
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>5 ERROR_ACCESS_DENIED</td>
  <td>The SERVICE_QUERY_STATUS access right had not been granted to the caller when the RPC context handle was created.</td>
 </tr><tr>
  <td>6 ERROR_INVALID_HANDLE</td>
  <td>The handle is no longer valid.</td>
 </tr><tr>
  <td>3 ERROR_PATH_NOT_FOUND</td>
  <td>The ImagePath of the service record identified by the hService parameter does not exist.</td>
 </tr><tr>
  <td>1115 ERROR_SHUTDOWN_IN_PROGRESS</td>
  <td>The system is shutting down.</td>
 </tr></tbody></table>
</dd></dl><p>If the type of the service record is SERVICE_KERNEL_DRIVER
or SERVICE_FILESYSTEM_DRIVER, the <span><a href="4f66d32e-2f4f-4482-998e-e5ccbb445223#gt_afc3f782-a908-486d-9c05-8a054cd9cc84" data-linktype="relative-path">SCM</a></span> 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>