32位系统:
RegistryKey keyLocalMachine = Registry.LocalMachine;
64位系统:
Microsoft.Win32.RegistryKey keyLocalMachine = Microsoft.Win32.RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, Microsoft.Win32.RegistryView.Registry64);
public static List<string> GetAutoCADLocations()
{
//用于存储系统中安装的AutoCAD路径列表
List<string> locations = new List<string>();
// 获取HKEY_LOCAL_MACHINE键
//RegistryKey keyLocalMachine = Registry.LocalMachine;
RegistryKey keyLocalMachine = Microsoft.Win32.RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, Microsoft.Win32.RegistryView.Registry64);
// 打开AutoCAD所属的注册表键:HKEY_LOCAL_MACHINE\Software\Autodesk\AutoCAD
RegistryKey keyAutoCAD = keyLocalMachine.OpenSubKey("Software\\Autodesk\\AutoCAD");
//获得表示系统中安装的各版本的AutoCAD注册表键
string[] cadVersions = keyAutoCAD.GetSubKeyNames();
foreach (string cadVersion in cadVersions)
{
//打开特定版本的AutoCAD注册表键
RegistryKey keyCADVersion = keyAutoCAD.OpenSubKey(cadVersion);
//获取表示各语言版本的AutoCAD注册表键值
string[] cadNames = keyCADVersion.GetSubKeyNames();
foreach (string cadName in cadNames)
{
if (cadName.EndsWith("804"))//中文版本
{
//打开中文版本的AutoCAD所属的注册表键
RegistryKey keyCADName = keyCADVersion.OpenSubKey(cadName);
//获取AutoCAD的安装路径
if (keyCADName.GetValue("Location") != null)
{
string location = keyCADName.GetValue("Location").ToString();
locations.Add(location);//将路径添加到列表中
}
}
}
}
return locations;//返回系统中安装的AutoCAD路径列表
}
参考:《AutoCAD VBA&VB.NET开发基础与实例教程》
参考:https://zhidao.baidu.com/question/551880021030941452.html
如有转载,请注明出处。