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 specific software. For example, we can use it to balance user load between license servers, create software usage statistics, or analyze user behavior patterns.
In this post, we share a C# code to perform queries to a FlexLM server. The obtained information can be processed to get the data 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 is an example of its use, where you will have to replace the values used with those from 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);
}

