读注册表问题(读取电脑已安装软件)
电脑是Win7 64位操作系统,
读取
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall 左边项
与
HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall 左边项,
读取结果都是按HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall这个来读了。请问这是怎么加速啊?
---------------------------------------------------------------
原代码如下:
void __fastcall TForm1::Button2Click(TObject *Sender)
{
ListView1->Clear();
ShowMessage("user");
ReadAllSoftInfo(ListView1,HKEY_CURRENT_USER,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall");
ShowMessage("LOCAL_MACHINE");
ReadAllSoftInfo(ListView1,HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall");
ShowMessage("LOCAL_MACHINE wow6432Node");
ReadAllSoftInfo(ListView1,HKEY_LOCAL_MACHINE,"SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall");
}
void TForm1::ReadAllSoftInfo(TListView *lv,HKEY root,String strParentKey)
{
TStringList *listKey=new TStringList;
TStringList *listValue=new TStringList;
TListItem *item=NULL;
String strSoftName="";
bool bSoftExist=false;
TRegistry *reg=new TRegistry;
reg->RootKey =root;
if(reg->OpenKey(strParentKey,false))
{
listKey->Clear();
reg->GetKeyNames(listKey);
reg->CloseKey();
ShowMessage(listKey->Count); //左边项共有几个子项
for(int i=0;i<listKey->Count;i++)
{
if(reg->OpenKey(strParentKey + "\\" + listKey->Strings[i],false))
{
listValue->Clear();
reg->GetValueNames(listValue);
if(listValue->IndexOf("DisplayName")>=0 && listValue->IndexOf("UninstallString")>=0)
{
strSoftName=reg->ReadString("DisplayName").Trim();
bSoftExist=false;
//应用程序是否重复
for(int j=0;j<lv->Items->Count;j++)
{
if(lv->Items->Item[j]->SubItems->Strings[0]==strSoftName)
{
bSoftExist=true;
break;
}
}
if(bSoftExist)
continue;
item=lv->Items->Add();
item->Caption =ListView1->Items->Count;
item->SubItems->Add( strSoftName);
if(listValue->IndexOf("ParentKeyName")>=0)
{
item->SubItems->Add("系统更新");
}
else if(listValue->IndexOf("SystemComponent")>=0)
{
if(reg->ReadInteger("SystemComponent") ==1)
item->SubItems->Add("系统组件") ;
else
item->SubItems->Add("应用程序") ;
}
else
item->SubItems->Add("应用程序") ;
item->SubItems->Add(reg->ReadString("DisplayVersion").Trim() );
item->SubItems->Add(reg->ReadString("UninstallString").Trim() );
//非应用程序,都不显示
if(!CheckBox1->Checked)
{
if(item->SubItems->Strings[1]!="应用程序")
item->Delete();
}
}
}
else
ShowMessage("open err : " + listKey->Strings[i]);
reg->CloseKey();
}
}
else
reg->CloseKey();
delete listKey,listValue;
delete reg;
}