話接上篇 [ASP.NET Core - 緩存之記憶體緩存(上)],所以這裡的目錄從 2.4 開始。 2.4 MemoryCacheEntryOptions MemoryCacheEntryOptions 是記憶體緩存配置類,可以通過它配置緩存相關的策略。除了上面講到的過期時間,我們還能夠設置下麵這些: ...
一、載入dll時寫註冊表
我們知道,dll載入到cad中後使用
HostApplicationServices.Current.RegistryProductRootKey()
就可以拿到當前cad的註冊表,那麼如果想在安裝程式時寫,此時並沒有cad的環境,要怎麼辦呢?
二、獲取所有已安裝的cad的註冊表路徑
cad在安裝後,會在註冊表的電腦\HKEY_LOCAL_MACHINE\SOFTWARE\Autodesk\Hardcopy
目錄下存放所有已安裝的cad的註冊表位置
如圖,由於我只安裝了一個,所以這裡只顯示一個,我們使用代碼即可獲取到所有的valueName值
public static List<string> GetHardcopyList()
{
List<string> list = new List<string>();
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;
}
拿到valueName值後,我們可以用如下方法寫上註冊表
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);
}
}
/// <summary>
/// 註冊dll
/// </summary>
/// <param name="dllFile">dll文件路徑</param>
/// <returns></returns>
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;
}
其中 dllFile為要寫入的dll路徑