VisionPro · C# · 加密狗检查程序
写VisionPro C#项目时,我们需要在程序的启动时加载各种配置文件,以及检查软件授权,以下代码即检查康耐视加密狗在线状态,如查无加密狗,关闭程序启动进程并抛出异常。
1 using System; 2 using Cognex.VisionPro; 3 using System.Windows.Forms; 4 5 ///6 /// 检测加密狗 7 /// 8 public void CheckVisionProDog() 9 { 10 try 11 { 12 if (CogMisc.GetLicensedFeatures(false).Count <= 0 || CogMisc.GetLicensedFeatures(false).HasChanged == false) 13 { 14 MessageBox.Show("未检测到加密狗,程序已退出!请联系供应商!", "警告"); 15 Application.Exit(); 16 } 17 } 18 catch (Exception ex) 19 { 20 MessageBox.Show("加密狗错误:" + ex.Message); 21 Application.Exit(); 22 } 23 }