# Protect a service

#### Overview

If your application runs as a service, say a Windows Service, you can protect your application with QLM as follows:

In your service startup code, add license validation when the service starts. If you are using the LicenseValidator class generated by the "Protect your application" wizard, call ValidateLicenseAtStartup when your service starts. If the call to ValidateLicenseAtStart up fails, you have two options:

1. Log an event in the Event Viewer with the error message returned by ValdiateLicenseAtStartup. The user would then need to launch the QLM License Wizard standalone application (with the proper arguments) to allow him/her to enter a license key.
2. Launch the QLM License Wizard standalone application (with the proper arguments) to allow the user to enter his license key. This may not be possible if your service does not have the privileges to launch a desktop app.

#### Configuration

If the service is running with the credentials of the Local System Account, you should configure QLM as follows in order to store license information at the machine level.

* QlmStoreKeysOptions: EStoreKeysPerMachine
* When launching the wizard, you must launch the wizard with elevated privileges.

If the service is running with the credentials of a specific user account, you should configure QLM as follows in order to store license information at the user level and machine level.

* QlmStoreKeysOptions: EStoreKeysPerUserAndMachine
* When launching the wizard, you must launch the wizard with the same account used to run the service.

#### Sample

A C# sample can be found here: %Public%\Documents\Quick License Manager\Samples\qlmpro\Windows\DotNet\C#\QlmServiceSample


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.soraco.co/docs/step-by-step-guides/protect-a-service.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
