I have developed an application and installed it on a client computer. In my application I need to get its installation path. My application has a registry entry at:
HKEY_LOCAL_MACHINE\SOFTWARE\MyApplication\[AppPath]
How can I read AppPath
using C#?
You can use Get-ChildItem to view registry keys and Set-Location to navigate to a key path. Registry values are attributes of a registry key. In the Registry drive, they are called Item Properties. A registry key can have both children keys and item properties.
Use the GetValue method, specifying the path and name) to read a value from registry key. The following example reads the value Name from HKEY_CURRENT_USER\Software\MyApp and displays it in a message box.
Usually 1 is true and 0 is false. However, this depends on how the application is implemented.
You're looking for the cunningly named Registry.GetValue
method.
string InstallPath = (string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\MyApplication\AppPath", "Installed", null); if (InstallPath != null) { // Do stuff }
That code should get your value. You'll need to be
using Microsoft.Win32;
for that to work though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With