static void Main(string[] args)
{
// 连接至 AutoCAD 应用程序
RegistryKey RegK = Registry.LocalMachine;
RegistryKey software = RegK.OpenSubKey("Software\\Autodesk\\AutoCAD\\R17.1", false);
if (software == null)
{
Console.WriteLine("AutoCAD 2008启动失败!");
return;
}
// 判断注册表文件是否已经存在
//if (IsReg)
//{
Console.WriteLine("注册表文件已存在,AutoCAD 2008正常启动..");
//Console.ReadLine();
System.Type AcadType = System.Type.GetTypeFromProgID("AutoCAD.Application");
Object acad= System.Activator.CreateInstance(AcadType);
AcadType.InvokeMember("visible", System.Reflection.BindingFlags.SetProperty, null, acad, new object[] { true });
Object documents = AcadType.InvokeMember("Documents", System.Reflection.BindingFlags.GetProperty, null, acad, null);
Object document = documents.GetType().InvokeMember("Add", System.Reflection.BindingFlags.InvokeMethod, null, documents, null);
//Autodesk.AutoCAD.Interop.AcadApplicationClass ICad = new AcadApplicationClass();
//ICad.Visible = true;
//ICad.WindowState =Autodesk.AutoCAD.Interop.
//return;
//}
}
// 注册表文件是否存在
static bool IsReg
{
get
{
RegistryKey Key = Registry.LocalMachine.OpenSubKey("Software\\Autodesk\\AutoCAD\\R17.1\\ACAD-6002:804\\Applications\\SmartSoft", false);
if (Key == null)
return false;
Key.Close();
return true;
}
}
}