Click here to Skip to main content
15,889,883 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good day everyone!
I just want to ask, how do you create a registry key in this location
Software\Microsoft\Windows\CurrentVersion\Uninstall

I tried the code below (I stole this somewhere :( , credit who ever coded it) and it is obviously adding a subkey in Software Key
C#
RegistryKey key = Registry.LocalMachine.OpenSubKey("Software",true);

key.CreateSubKey("AppName");
key = key.OpenSubKey("AppName", true);


key.CreateSubKey("AppVersion");
key = key.OpenSubKey("AppVersion", true);

key.SetValue("yourkey", "yourvalue");


So, I tried it by changing the
C#
RegistryKey key = Registry.LocalMachine.OpenSubKey("Software",true);

to
C#
RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall");

and it is now giving me an exception which is
'System.UnauthorizedAccessException' occurred in mscorlib.dll

Thank you for the help everyone!
Posted
Updated 2-Oct-14 21:20pm
v2
Comments
Richard MacCutchan 3-Oct-14 4:06am    
You need to run with administrator privilege to add items to the HKLM hive.
gaga blues 3-Oct-14 4:26am    
Yes right now, the request priveldge is "requireAdminitrator" so I am running the code with admin rights.
Richard MacCutchan 3-Oct-14 4:30am    
Not according to the error message.
BillWoodruff 3-Oct-14 4:40am    
See if this is useful:


http://stackoverflow.com/a/14108139/133321

note: I have not tried this myself.
gaga blues 7-Oct-14 10:29am    
Ok i'll go check this one out. I'll let you know how it turned out. Thank you so much!

1 solution

Entries in Software\Microsoft\Windows\CurrentVersion\Uninstall are typically created by Windows Installer. Hence create an intsaller for your program, and do not try to write there from your application proper!
 
Share this answer
 
Comments
gaga blues 7-Oct-14 10:28am    
Thanks for the help! Well, there is a situation that the application that I am trying to check in the registry can run even when the key of that application is deleted so I want regenerate that key in the registry.

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