Language: EN

consultar-servidor-de-licencias-flexlm-desde-c

Check FlexLM License Server from C#

FlexLM is a widely used license monitoring software in the corporate world. FlexLM is used by major software companies to manage the use of their floating licenses, especially in the case of CAD programs.

Sometimes it is useful to be able to run queries to a FlexLM server to obtain information about the licenses in use and available on the server, for a specific software. For example, we can use it to balance the user load between license servers, make software usage statistics, or analyze user behavior patterns.

In this post we share some C# code to make queries on a FlexLM server. The information obtained can be processed to obtain the data that your application needs.

To make the query we have this function.

private string queryFLEXLMLicense(string flexLMPath, string port, string host, string license)
{
    string rdo = "";
    string args = String.Format("lmstat -c {0}@{1} -f {2}", port, host, license);

    ProcessStartInfo info = new ProcessStartInfo(flexLMPath, args);
    info.WindowStyle = ProcessWindowStyle.Hidden;
    info.UseShellExecute = false;
    info.RedirectStandardOutput = true;

    using (Process p = Process.Start(info))
    {
        string output = p.StandardOutput.ReadToEnd();

        // standard output must be read first; wait max 5 minutes
        if (p.WaitForExit(300000))
        {
            p.WaitForExit();
        }
        else
        {
            // kill the lmstat instance and move on
            p.Kill();
            p.WaitForExit();
        }
        rdo += output;
    }
}

Here’s an example of its use, where you’ll have to replace the values used with those of your installation.

public void main()
{

    string flexLMPath = @"C:\Program Files\flexLM\lmutil.exe";   //replace with the path to lmutil.exe on your PC
    string port = "27001";
    string host = "XXX.YYY.com";    //replace with the address of the license server
    string license = "ZZZ";        //replace with the name of the license to query
    
    string license = queryLicenses(flexLMPath, port, host, license);
}