• 注册表获取exe位置+ Process类启动exe+参数让exe打开指定文件


      /// <summary>
            /// 启动本机的cad,并且在cad中浏览dwg图
            /// </summary>
            /// <param name="path">cad.exe的位置</param>
            /// <param name="dwgfile">dwgfile的完整路径</param>
            public void StartCad2004(string path,string dwgfile)
            {
                Process p = new Process();
                p.StartInfo.FileName = path;  //启动本机的cad
                p.StartInfo.Arguments = dwgfile;//设置cad要打开的dwg文件
                  p.Start();////启动本机的cad
            }
    
           /// <summary>
           /// 获取cad路径
           /// </summary>
           /// <param name="path">从注册表中读取的cad位置</param>
           /// <returns></returns>
            public bool GetCadPath(out string path)
            {
                path = "";
                RegistryKey key_localMachine = Registry.LocalMachine;
                //RegistryKey key_cad = key_localMachine.OpenSubKey("SOFTWARE\\Autodesk\\AutoCAD\\R16.2\\ACAD-4001:804\\", false);//cad2006注册表地址
                //RegistryKey key_cad = key_localMachine.OpenSubKey("SOFTWARE\\Autodesk\\AutoCAD\\R16.0\\ACAD-201:804\\", false);//cad2004注册表地址
                //任意版本cad启动程序
                /*这个值的特点, "exe" "dwg文件"  
                 * 
                 */
                RegistryKey key_cad = key_localMachine.OpenSubKey("SOFTWARE\\Classes\\Applications\\acad.exe\\shell\\open\\command", false);
                if (key_cad != null)
                {
                    string cadpath = key_cad.GetValue("").ToString(); //获取启动路径
                    MatchCollection mc= Regex.Matches(cadpath, "\"(?<cadpath>.*)\" "); //仅获取第一个acad.exe路径
                    cadpath = mc[0].Groups["cadpath"].Value;
                    path = cadpath;
                    return true;
                }
                return false;
            }
  • 相关阅读:
    5G和物联网:面临各种安全挑战的新兴技术
    嵌入式Linux系统的几大组件!
    物联网应用开发如何平衡用户体验与隐私安全?
    我们需要什么数据架构?
    2020.7.30
    2020.7.29
    2020.7.28
    2020.7.27
    2020.7.26 + 周报(3)
    2020.7.25
  • 原文地址:https://www.cnblogs.com/imihiroblog/p/2461560.html
Copyright © 2020-2023  润新知