Does anyone have any experience querying FlexLM? (At a minimum) I need to be able to tell if a license is available for a particular application. Previously this was done by checking what processes were running, but if I can somehow query FlexLM, that would be more elegant!
I've done this recently. I needed to query FlexLM license servers, and discover what licenses were outstanding/available. I didn't find a reasonable API for this, so I instead just launched lmutil, asked it to query the server, and parsed laboriously through the textual results. A pain, but it worked, and really didn't take that long to put together.
Find your copy of lmutil.exe, and run it with either the -a or -i switch, depending on the data you want to gather. Pass it the server and port you wish you query, with the -c switch. Yes, you will need to know the port the FlexLM daemon's running on. There's a standard port, but there's nothing forcing it to run on that port only.
Since I needed to run this regularly, and I needed to query thousands of daemons, I drove lmutil from an application - something like:
string portAtHost = "[email protected]";
string args = String.Format("lmstat -c {0} -a -i", portAtHost);
ProcessStartInfo info = new ProcessStartInfo(@"lmutil.exe", 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(); // per MSDN guidance: Process.WaitForExit Method
}
else
{
// kill the lmstat instance and move on
log.Warn("lmstat did not exit within timeout period; killing");
p.Kill();
p.WaitForExit(); // Process.Kill() is asynchronous; wait for forced quit
}
File.WriteAllText("c:\file.lmout", output);
}
...then you need to parse through the results. Depending what you're looking for, this could be as simple as splitting the result lines over space characters.