Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am trying to extract uninstall string from the registry for the programs installed.
I have written the following code to loop thorough the programs.
VB
Dim Software As String = Nothing
       'The registry key will be held in a string SoftwareKey.
       Dim SoftwareKey As String = "SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products"
       '"\UserData\S-1-5-18\Products"
       Using rk As RegistryKey = Registry.LocalMachine.OpenSubKey(SoftwareKey)
           For Each skName In rk.GetSubKeyNames
Next
        End Using


But i am getting null/Nothing from the OpenSubKey() method, If i give up to the following path "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer" it is returning value.
I have checked the full path in registry, it exists there. Tried by changing permissions also, which is not working. Can you help?
I am using Windows 7 64 bit OS
Posted
Updated 2-Jun-14 22:21pm
v2

1 solution

Make sure you open the correct hive depending on machine configuration (64 or 32 bit).

This code might work better for you;
VB
Sub Main()
    Using hklm As RegistryKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, IIf(Environment.Is64BitOperatingSystem, RegistryView.Registry64, RegistryView.Registry32))
        Using key As RegistryKey = hklm.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products")
            Console.WriteLine(key)
        End Using
    End Using
End Sub

Hope this helps,
Fredrik
 
Share this answer
 
Comments
phil.o 3-Jun-14 5:45am    
Smart! My 5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900