110,571
社区成员
发帖
与我相关
我的任务
分享
public static string GetProductCode(string displayName)
{
string productCode = string.Empty;
string[] SubKeyNames;
//string[] valueNames;
string displayname;
//string info;
// 如果是32位操作系统,(或者系统是64位,程序也是64位)
string bit32 = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
// 如果操作系统是64位并且程序是32位的
string bit64 = @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall";
RegistryKey localMachine = Registry.LocalMachine;
RegistryKey Uninstall = localMachine.OpenSubKey(bit32, true);
SubKeyNames = Uninstall.GetSubKeyNames();
foreach (string subkey in SubKeyNames)
{
RegistryKey productcode = Uninstall.OpenSubKey(subkey);
//valueNames = productcode.GetValueNames();
//foreach (string valueName in valueNames)
//{
// int i = valueName.IndexOf("DisplayName");
// if (i != -1)
// {
// RegistryKey myreg = Uninstall.OpenSubKey();
// info = myreg.GetValue(valueName).ToString();
// MessageBox.Show("结果的值是:" + info);
// }
//}
displayname = productcode.GetValue("DisplayName").ToString();
//if (displayname == displayName)
if (displayname.IndexOf( displayName)!=-1)
{
MessageBox.Show(displayname);
string uninstallString = productcode.GetValue("UninstallString").ToString();
string[] strs = uninstallString.Split(new char[2] { '{', '}' });
productCode = strs[1];
return productCode;
}
}
return productCode;
}
public static string GetProductCode(string displayName)
{
string productCode = string.Empty;
string[] SubKeyNames;
string[] valueNames;
string displayname;
string info;
// 如果是32位操作系统,(或者系统是64位,程序也是64位)
string bit32 = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall";
// 如果操作系统是64位并且程序是32位的
string bit64 = "SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall";
RegistryKey localMachine = Registry.LocalMachine;
RegistryKey Uninstall = localMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall", true);
SubKeyNames = Uninstall.GetSubKeyNames();
foreach (string subkey in SubKeyNames)
{
RegistryKey productcode = Uninstall.OpenSubKey(subkey);
valueNames = productcode.GetValueNames();
foreach (string valueName in valueNames)
{
if(valueName=="DisplayName")
{
RegistryKey myreg = Uninstall.OpenSubKey(subkey);
info = myreg.GetValue(valueName).ToString();
MessageBox.Show(subkey+"的程序名称是:" + info);
}
}
//displayname = productcode.GetValue("DisplayName").ToString();
////if (displayname == displayName)
//if (displayname.IndexOf( displayName)!=-1)
//{
// MessageBox.Show(displayname);
//string uninstallString = productcode.GetValue("UninstallString").ToString();
//string[] strs = uninstallString.Split(new char[2] { '{', '}' });
//productCode = strs[1];
//return productCode;
//}
}
return productCode;
}