I am trying to create an registry, but it give me following message.
Access to the registry key ‘HKEY_LOCAL_MACHINE\Software\aspire’ is denied
And following is my code.
protected void CreateRegistry()
{
dtStartDate = DateTime.Now;
string strUser = Environment.UserDomainName + "\\" + Environment.UserName;
RegistrySecurity rs = new RegistrySecurity();
//rs.AddAccessRule(new RegistryAccessRule("Administrator", RegistryRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.InheritOnly, AccessControlType.Allow));
rs.AddAccessRule(new RegistryAccessRule(strUser, RegistryRights.FullControl, InheritanceFlags.None, PropagationFlags.None, AccessControlType.Allow));
RegistryKey regDate = null;
try
{
regDate = Registry.LocalMachine.CreateSubKey("Software\\aspire", RegistryKeyPermissionCheck.Default, rs);
if (regDate != null)
{
regDate.SetValue("Date", dtStartDate.ToString(strDateFormat));
regDate.Close();
MessageBox.Show("created");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
when i am executing the same code in different system, the code runs correctly.
b’coz there isn’t created any user on that system.
But now in this system i have created 2 user from control panel, and this is happening with me.
Both Systems are running on Windows 7.
PLease help
Thank you
If you are using windows 7, start run the application in administrator mode. if you are debugging from visual studio, start visual studio in administrator mode.