gpt4 book ai didi

c# - 从 ProgID 获取 dll 目录

转载 作者:行者123 更新时间:2023-12-04 18:23:19 25 4
gpt4 key购买 nike

我正在使用

Type progID =  Type.GetTypeFromProgID(SimpleConfiguration.currentConfiguration.OPOSWrappedSO);

我还想将此 dll 的路径添加到 PATH 环境变量中。有没有办法从类型中获取目录?

谢谢

最佳答案

    public static string GetDLLPathFromClassID(string classID)
{
var regPath = @"\CLSID\" + classID + @"\InProcServer32\";
return GetDefaultRegistryValue(Registry.ClassesRoot, regPath);
}

public static string GetClassIDFromProgID(string progID)
{
var regPath = progID + @"\CLSID\";
return GetDefaultRegistryValue(Registry.ClassesRoot, regPath);
}

private static string GetDefaultRegistryValue(RegistryKey rootKey, string regPath)
{
try
{
var regPermission = new RegistryPermission(RegistryPermissionAccess.Read,
@"HKEY_CLASSES_ROOT\" + regPath);
regPermission.Demand();
using (var regKey = rootKey.OpenSubKey(regPath))
{
if (regKey != null)
{
string defaultValue = (string) regKey.GetValue("");
{
return defaultValue;
}
}
}
}catch(Exception e)
{
//log error
}
return "";
}

public static string GetDLLDirectoryFromProgID(string progID)
{
var classID = GetClassIDFromProgID(progID);
var fileName = GetDLLPathFromClassID(classID);
if(string.IsNullOrEmpty(fileName))
{
return "";
}
return Path.GetDirectoryName(fileName);
}

关于c# - 从 ProgID 获取 dll 目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10214183/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com