- namespace AutoActivateVisionPro
- {
- class Program
- {
- private static void Activate()
- {
- var cmd = new System.Diagnostics.Process();
- cmd.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
- cmd.StartInfo.FileName = "cmd";
- cmd.StartInfo.CreateNoWindow = true;
- cmd.StartInfo.UseShellExecute = false;
- cmd.StartInfo.RedirectStandardInput = true;
- cmd.StartInfo.RedirectStandardOutput = true;
-
- cmd.OutputDataReceived += (sender, e) =>
- {
- if (!string.IsNullOrEmpty(e.Data))
- {
- string[] outs = e.Data.Split(new char[] { '\n', '\r' });
- for (int i = 0; i < outs.GetLength(0); i++)
- {
- System.Console.WriteLine(outs[i]);
- }
- }
- };
- cmd.Start();
- cmd.BeginOutputReadLine();
-
- var cmdWriter = cmd.StandardInput;
-
- // 切换到C盘
- cmdWriter.WriteLine("C:");
-
- // 获取VP的密匙管理中心的路径
- string rootFolder = string.Empty;
- if (System.Environment.Is64BitOperatingSystem)
- {
- rootFolder = """ + "C:/Program Files (x86)/Common Files/Cognex/Software Licensing Center/" + """;
- }
- else
- {
- rootFolder = """ + "C:/Program Files/Common Files/Cognex/Software Licensing Center/" + """;
- }
-
- // 切换执行目录到VP密匙管理中心目录
- cmdWriter.WriteLine("cd " + rootFolder);
-
-
- // 1. 将命名为CVL.zip的VisionPro激活备份文件添加到项目资源中
- // 2. 解压该资源文件到系统临时目录
- var strTmpDirectory = System.IO.Path.GetTempPath() + "CVL.zip";
- System.IO.File.WriteAllBytes(strTmpDirectory, Properties.Resources.CVL);
-
- // 加载VP激活备份文件
- cmdWriter.WriteLine(@"cogslc --restore " + """ + strTmpDirectory + """);
-
- // 执行激活命令
- cmdWriter.WriteLine(@"cogslc --emergency install --edir ./Emergency/VisionPro");
- cmdWriter.Close();
- cmd.Close();
- }
-
-
- static void Main(string[] args)
- {
- // 需要保证程序以管理员权限运行
- if (!string.IsNullOrEmpty(System.Environment.GetEnvironmentVariable("VPRO_ROOT")))
- {
- Program.Activate();
- }
- }
- }
- }
复制代码
---------------------
作者:zhy29563
来源:CSDN
这位同学研究的已经非常透彻了.
|