2012-11-14 80 views
0

我使用GetSubKeysNames函數從{HKEY_LOCAL_MACHINE \ Software \ Microsoft \ Windows \ CurrentVersion \ Uninstall}中獲取子項。但它返回不同的子項計數。在C#中返回371個子項,在Visual Basic中返回61個子項。我在哪裏錯了?GetSubKeyNames函數返回C#和Visual Basic中的不同子鍵

這是一些代碼和圖片。

C#

string[] deneme = unistallKey.GetSubKeyNames(); 

enter image description here

VB

Dim deneme() As String = UninstallKey.GetSubKeyNames 

enter image description here

+0

看看這個: http://stackoverflow.com/questions/3112181/registry-getsubkeynames-lists-different-keys-than-regedit –

+0

什麼是'UninstallKey'?你應該在你獲得子密鑰的地方發佈代碼,而不是在你使用它們的地方。 – DjSol

+0

Unistallkey是HKEY_LOCAL_MACHINE \ Software \ Microsoft \ Windows \ CurrentVersion \ Uninstall,我想要HKEY_LOCAL_MACHINE \ Software \ Microsoft \ Windows \ CurrentVersion \ Uninstall的子項。我沒有使用,我正試圖在這裏獲得它們。 – mburakerbay

回答

0

可能是部分程序是在32位安裝的,有些是在64位。 枚舉通過以下重點:

HKEY_LOCAL_MACHINE \ SOFTWARE \ WOW6432node \

+0

我正在檢查他們,但問題是在HKEY_LOCAL_MACHINE \ Software \ Microsoft \ Windows \ CurrentVersion \ Uninstall下 – mburakerbay

1

我有同樣的問題,並使用下面的代碼,問題解決了。

Dim rk1 As RegistryKey = Microsoft.Win32.RegistryKey.OpenBaseKey _ 
            (Microsoft.Win32.RegistryHive.LocalMachine, Microsoft.Win32.RegistryView.Registry64) 
     Dim rk2 As RegistryKey = Microsoft.Win32.RegistryKey.OpenBaseKey _ 
            (Microsoft.Win32.RegistryHive.LocalMachine, Microsoft.Win32.RegistryView.Registry64) 
     Dim rk3 As RegistryKey = Microsoft.Win32.RegistryKey.OpenBaseKey _ 
            (Microsoft.Win32.RegistryHive.LocalMachine, Microsoft.Win32.RegistryView.Registry64) 

    rk1 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64) 

    regpath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" 

    rk2 = rk1.OpenSubKey(regpath) 

    For Each subk As String In rk2.GetSubKeyNames 

     rk3 = rk2.OpenSubKey(subk, False) 

     value = rk3.GetValue("DisplayName", "") 

     If value <> "" Then 
      includes = True 
      If value.IndexOf("Hotfix") <> -1 Then includes = False 
      If value.IndexOf("Security Update") <> -1 Then includes = False 
      If value.IndexOf("Update for") <> -1 Then includes = False 
      If value.IndexOf("Service Pack") <> -1 Then includes = False 

      For vAtual = 0 To UBound(Softwares) 
       If value = Softwares(vAtual) Then 
        includes = False 
       End If 
      Next 

      If includes = True Then 
       gridSoft.Rows.Add(value, rk3.GetValue("InstallDate", ""), rk3.GetValue("UninstallString", ""), rk3.GetValue("EstimatedSize", ""), rk3.GetValue("InstallLocation", ""), rk3.GetValue("Publisher", "")) 
       Softwares(vCont) = value 
       vCont = vCont + 1 
      End If 

     End If 
    Next