/// <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; }