CAD secondary development, write registry in the installer
1. Write registry when loading dll
We know that the dll is loaded into cad and used
HostApplicationServices.Current.RegistryProductRootKey()
You can get the current cad registry, so if you want to write when installing the program, there is no cad environment at this time, what should you do?
Second, get the registry path of all installed cad
After cad is installed, it will store the registry locations of all installed cad in the Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Autodesk\Hardcopy
directory of the registry
As shown in the picture, since I only installed one, only one is displayed here, and we can get all valueName values by using the code
public static List GetHardcopyList()
{
List list = new List();
var key = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Autodesk\Hardcopy");
if (key != null)
{
string[] subKeyNames = key. GetValueNames();
subKeyNames.Count().Prompt();
foreach (string name in subKeyNames)
{
list. Add(name);
}
}
return list;
}
After getting the valueName value, we can use the following method to write the registration form
public static void WriteZcb()
{
var names = GetHardcopyList();
var dllFile = "D:\\123.dll";
foreach (var name in names)
{
var address = "SOFTWARE\\" + name + "\\Applications";
RegisteringCAD(address, dllFile);
}
}
///
/// Register dll
///
/// dll file path
///
public static bool RegisteringCAD(string address, string dllFile)
{
RegistryKey user = Registry. CurrentUser. OpenSubKey(address, true);
if (user == null)
{
return false;
}
RegistryKey keyUserApp = user.CreateSubKey(Path.GetFileNameWithoutExtension(dllFile));
keyUserApp.SetValue("DESCRIPTION", Path.GetFileNameWithoutExtension(dllFile), RegistryValueKind.String);
keyUserApp.SetValue("LOADCTRLS", 2, RegistryValueKind.DWord);
keyUserApp.SetValue("LOADER", dllFile, RegistryValueKind.String);
keyUserApp.SetValue("MANAGED", 1, RegistryValueKind.DWord);
return true;
}
where dllFile is the dll path to be written