写注册表,带权限控制

public void Write()
{
RegistrySecurity rsy = new RegistrySecurity();

RegistryAccessRule rar = new RegistryAccessRule(Environment.UserDomainName +

"\\" + Environment.UserName, RegistryRights.ReadKey | RegistryRights.WriteKey |

RegistryRights.Delete, InheritanceFlags.ContainerInherit, PropagationFlags.None,

AccessControlType.Allow);

rsy.AddAccessRule(rar);

Microsoft.Win32.RegistryKey rootKey = Microsoft.Win32.Registry.LocalMachine;//本地计算机数据的配置

Microsoft.Win32.RegistryKey runKey = rootKey.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", RegistryKeyPermissionCheck.ReadWriteSubTree, rsy);
}

posted @ 2015-05-31 15:43  清幽紫竹  Views(152)  Comments(0)    收藏  举报