المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : How to give access to ServiceAccount.LocalSystem to Registry (HKCU)



C# Programming
03-13-2012, 09:53 AM
Hi... I tried to search but I think I didnt found the answer thats why Im posting my query here. If some instance theres already post that can answer my question, can you direct me to that path?

Heres my problem:

I create a services and installed it as:

processInstaller.Account = ServiceAccount.LocalSystem;
Upon start it modify and/or delete some registry entry under HKEY_CURRENT_USER. The current account user is an Admin, but still it give me an error message "Could not start the Service on Local Computer. Error 5: Access is denied." upon starting the service at Services and Applications.

Below is my code upon changing registry entry.

string user = System.Security.Principal.WindowsIdentity.GetCurrent().Name; RegistrySecurity rs = new RegistrySecurity(); rs.AddAccessRule(new RegistryAccessRule(user, RegistryRights.ReadKey | RegistryRights.WriteKey, InheritanceFlags.None, PropagationFlags.None, AccessControlType.Allow)); RegistryKey key; key = Registry.CurrentUser.OpenSubKey(path, true);key.SetAccessControl(rs);..(changing of registry here).