C#:查询FlexLM许可证管理器

有没有人有任何查询FlexLM的经验? (至少)我需要能够判断某个特定应用程序的许可证是否可用。 以前这是通过检查正在运行的进程来完成的,但如果我能以某种方式查询FlexLM,那将更加优雅!

我最近这样做了。 我需要查询FlexLM许可证服务器,并发现哪些许可证是未完成/可用的。 我没有为此找到合理的API,所以我只是启动了lmutil,要求它查询服务器,并通过文本结果费力地解析。 痛苦,但它起作用,并且真的没有花那么长时间拼凑起来。

找到lmutil.exe的副本,并使用-a或-i开关运行它,具体取决于您要收集的数据。 使用-c开关将您希望查询的服务器和端口传递给它。 是的,您需要知道FlexLM守护程序正在运行的端口。 有一个标准端口,但没有什么强迫它只在该端口上运行。

由于我需要定期运行,并且需要查询数千个守护进程,因此我从应用程序中驱动了lmutil – 类似于:

string portAtHost = "1708@my.server.com"; 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); } 

…然后你需要解析结果。 根据您的需求,这可能就像将结果行分割为空格字符一样简单。