2024年5月2日发(作者:)
这个方法是根据软件名称获取软件路径,稍微修改一下就会得到获取所有软件的方法
///
/// 软件是否安转
///
/// 软件名称
/// 安装路径
///
private bool GetSoftWare(string SoftWareName, out string SoftWarePath)
{
SoftWarePath = ;
List
(sRoot);
(tConfig);
(tUser);
(achine);
(manceData);
();
Dictionary
string SubKeyName = @"SoftwareMicrosoftWindowsCurrentVersionUninstall";
foreach (RegistryKey Registrykey in RegistryKeys)
{
using (RegistryKey RegistryKey1 = bKey(SubKeyName, false))
{
if (RegistryKey1 == null)//判断对象不存在
continue;
if (KeyNames() == null)
continue;
string[] KeyNames = KeyNames();
foreach (string KeyName in KeyNames)//遍历子项名称的字符串数组
{
using (RegistryKey RegistryKey2 = bKey(KeyName,
false))//遍历子项节点
{
if (RegistryKey2 == null)
continue;
string SoftwareName = ue("DisplayName",
"").ToString();//获取软件名
string InstallLocation = ue("InstallLocation",
"").ToString();//获取安装路径
if (!OrEmpty(InstallLocation)
&& !OrEmpty(SoftwareName))
{
if (!nsKey(SoftwareName))
(SoftwareName, InstallLocation);
}
}
}
}
}
if ( <= 0)
return false;
foreach (string SoftwareName in )
{
if (ns(SoftWareName))
{
SoftWarePath = Softwares[SoftwareName];
return true;
}
}
return false;
}
这个方法是修改之后的
///
/// 本机所有安转软件
///
///
private static Dictionary
{
List
(sRoot);
(tConfig);
(tUser);
(achine);
(manceData);
();
Dictionary
string SubKeyName = @"SoftwareMicrosoftWindowsCurrentVersionUninstall";
foreach (RegistryKey Registrykey in RegistryKeys)
{
using (RegistryKey RegistryKey1 = bKey(SubKeyName, false))
{
if (RegistryKey1 == null)//判断对象不存在
continue;
if (KeyNames() == null)
continue;
string[] KeyNames = KeyNames();
foreach (string KeyName in KeyNames)//遍历子项名称的字符串数组
{
using (RegistryKey RegistryKey2 = bKey(KeyName,
false))//遍历子项节点
{
if (RegistryKey2 == null)
continue;
string SoftwareName = ue("DisplayName",
"").ToString();//获取软件名
string InstallLocation = ue("InstallLocation",
"").ToString();//获取安装路径
if (!OrEmpty(InstallLocation)
&& !OrEmpty(SoftwareName))
{
if (!nsKey(SoftwareName))
(SoftwareName, InstallLocation);
}
}
}
}
}
return Softwares;
}
这样就可以返回这个的安装列表,如果想获取更多安装信息的话添加即可。
sRoot 对应注册表 HKEY_CLASSES_ROOT
tConfig 对应注册表 HKEY_CURRENT_CONFIG
tUser 对应注册表 HKEY_CURRENT_USER
achine 对应注册表 HKEY_LOCAL_MACHINE
manceData 对应注册表 HKEY_PERFORMANCE_DATA
对应注册表 HKEY_USERS
由于安装的路径及账号的问题软件的同一个软件可能在不同的电脑上写在了不同的注册表中,因此要全
部遍历才可以获取全部软件的安装信息。
发布者:admin,转转请注明出处:http://www.yc00.com/news/1714586278a2475279.html
评论列表(0条)