DEV Community

Soraco Technologies
Soraco Technologies

Posted on

How to Check if a .NET License is Activated in 5 Lines of Code

Your .NET app needs to know: Is there a valid license on this computer?

Here's how to check in 5 lines.

The Code

using QLM.LicenseLib;

var lv = new LicenseValidator("settings.xml");
bool needsActivation = false;
string errorMsg = string.Empty;

bool isActivated = lv.ValidateLicenseAtStartup(
    ELicenseBinding.ComputerName,
    ref needsActivation,
    ref errorMsg
);

if (isActivated)
{
    Console.WriteLine("License is valid - app can run");
}
else
{
    Console.WriteLine("No valid license: " + errorMsg);
}
Enter fullscreen mode Exit fullscreen mode

That's it. 5 lines.

What ValidateLicenseAtStartup Does

  1. Looks for stored license on the computer
  2. Validates signature (RSA-2048)
  3. Checks expiry (for trials/subscriptions)
  4. Optionally contacts server (if online validation enabled)
  5. Returns true/false

Three Possible Outcomes

1. License is valid (isActivated = true)

if (isActivated)
{
    RunApp();
}
Enter fullscreen mode Exit fullscreen mode

2. No license found (needsActivation = true)

if (needsActivation)
{
    ShowActivationDialog();
}
Enter fullscreen mode Exit fullscreen mode

3. License exists but invalid (isActivated = false)

if (!isActivated)
{
    Console.WriteLine("Error: " + errorMsg);
    // Expired, wrong version, revoked, etc.
}
Enter fullscreen mode Exit fullscreen mode

Real Example: Desktop App

using System;
using QLM.LicenseLib;

class Program
{
    static void Main(string[] args)
    {
        if (IsLicenseActivated())
        {
            Console.WriteLine("Starting application...");
            RunApp();
        }
        else
        {
            Console.WriteLine("Please activate your license.");
        }
    }

    static bool IsLicenseActivated()
    {
        var lv = new LicenseValidator("settings.xml");

        bool needsActivation = false;
        string errorMsg = string.Empty;

        bool isValid = lv.ValidateLicenseAtStartup(
            ELicenseBinding.ComputerName,
            ref needsActivation,
            ref errorMsg
        );

        if (needsActivation)
        {
            Console.WriteLine("No license found - activation required");
            return false;
        }

        if (!isValid)
        {
            Console.WriteLine($"License invalid: {errorMsg}");
            return false;
        }

        return true;
    }

    static void RunApp()
    {
        Console.WriteLine("App is running with valid license");
        // Your application code here
    }
}
Enter fullscreen mode Exit fullscreen mode

Different License Types

This works for all license types:

Permanent licenses:

  • No expiry date
  • Valid forever

Trial licenses:

  • Expires after X days
  • ValidateLicenseAtStartup returns false after expiry

Subscription licenses:

  • Renews periodically
  • Auto-extends when customer pays

Hardware Binding

You can bind licenses to different identifiers:

// Computer Name (default)
lv.ValidateLicenseAtStartup(
    ELicenseBinding.ComputerName,
    ref needsActivation,
    ref errorMsg
);

// MAC Address
lv.ValidateLicenseAtStartup(
    ELicenseBinding.MacAddress,
    ref needsActivation,
    ref errorMsg
);

// Motherboard Serial
lv.ValidateLicenseAtStartup(
    ELicenseBinding.MotherboardSerialNumber,
    ref needsActivation,
    ref errorMsg
);
Enter fullscreen mode Exit fullscreen mode

Most common: ComputerName (easy for users)

Most secure: MotherboardSerialNumber (survives OS reinstalls)

Offline vs Online Validation

Offline (default):

  • Validates license signature locally
  • Checks expiry date
  • No internet required

Online (optional):

  • Contacts QLM License Server
  • Detects revoked licenses
  • Checks for subscription renewals

Enable online validation:

lv.QlmLicenseObject.ValidateOnServer = true;
Enter fullscreen mode Exit fullscreen mode

When to Call This

At application startup:

static void Main(string[] args)
{
    if (!IsLicenseActivated())
    {
        Environment.Exit(0);
    }

    RunApp();
}
Enter fullscreen mode Exit fullscreen mode

Before accessing paid features:

public void UnlockPremiumFeature()
{
    if (!IsLicenseActivated())
    {
        MessageBox.Show("This feature requires a license");
        return;
    }

    // Premium feature code
}
Enter fullscreen mode Exit fullscreen mode

Error Messages

Common errorMsg values:

  • "The license key is invalid" → Wrong key or signature
  • "The license has expired" → Trial/subscription ended
  • "The license is disabled" → Revoked by admin
  • "The product version is incorrect" → License for different version

Supported Platforms

  • Windows: .NET Framework 2.x / 4.x, .NET 6/7/8/9/10
  • Cross-platform: .NET 6/7/8/9/10 (macOS, Linux)
  • Mobile: Android, iOS (.NET MAUI, Xamarin)

Quick License Manager

This uses Quick License Manager (QLM).

Pricing (per developer):

  • QLM Express: $200/year
  • QLM Professional: $699/year
  • QLM Enterprise: $999/year

Features:

  • RSA-2048 + AES-256 encryption
  • Online & offline activation
  • Trial & subscription support
  • 12 e-commerce integrations
  • Customer self-service portal
  • Floating licenses (Enterprise)

Download 30-day trial

Resources

Related articles:


Questions? Drop them in the comments! 👇

Quick License Manager by Soraco Technologies — https://soraco.co

Top comments (0)