Click here to Skip to main content
15,887,821 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I have C# application, i want to check tool which is registered or not in the registry. if the tool is registered i want to get the path and execute that exe in command prompt?

can anyone suggest me, How to do this?

Thanks.

What I have tried:

using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\PenMount Windows Universal Driver"))
             {
                 if (rk != null)
                 {
                     this.Logger.Error("PenMount exists");
                 }
                 else
                 {
                     this.Logger.Error("not exists");
                 }
             }


but rk is always getting null.
Posted
Updated 12-Sep-17 9:25am
v2
Comments
Richard MacCutchan 12-Sep-17 11:16am    
Have you looked in the Registry to see if the key exists, or checked the error code to find out why?
sri durga 12-Sep-17 11:26am    
I checked for other softwares. its giving null even the key exists in the registry.
Richard MacCutchan 12-Sep-17 11:38am    
Then you need to check the error code when it returns null.

1 solution

The most likely cause is that you're running a 32-bit application on a 64-bit OS:
c# - OpenSubKey() returns null for a registry key that I can see in regedit.exe - Stack Overflow[^]

By default, you'll be looking in HKLM\Software\Wow6432Node, thanks to the registry redirector:
Registry Redirector (Windows)[^]

Assuming you're using .NET 4.0 or later, you'll need to specify the registry view:
using (var hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64))
using (var key = hklm.OpenSubKey(@"SOFTWARE\PenMount Windows Universal Driver"))
{
   // key now points to the 64-bit key
}

If you're using an earlier version, you'll need some P/Invoke calls instead:
How to read the 64 bit registry from a 32 bit application or vice versa | Rhyous[^]
 
Share this answer
 
Comments
sri durga 13-Sep-17 11:00am    
the above solution working , but i am trying to get the path where it installed from the registry. can you help me how to get the path from the registry.

Thanks for your help.

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