Ich versuche, eine Regel für den Registrierungszugriff auf einem entfernten Computer festzulegen:
using (RegistryKey localMachineKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, serverName))
{
RegistrySecurity rs = new RegistrySecurity();
rs.AddAccessRule(new RegistryAccessRule(userName, RegistryRights.FullControl, AccessControlType.Allow));
using (RegistryKey subKey = localMachineKey.CreateSubKey(registryKey))
{
subKey.SetValue(name, value);
subKey.SetAccessControl(rs);
}
}
führt dies zu der folgenden Ausnahme:
System.NotSupportedException: The supplied handle is invalid. This can happen when trying to set an ACL on an anonymous kernel object.
at System.Security.AccessControl.NativeObjectSecurity.Persist(String name, SafeHandle handle, AccessControlSections includeSections, Object exceptionContext)
at System.Security.AccessControl.NativeObjectSecurity.Persist(SafeHandle handle, AccessControlSections includeSections, Object exceptionContext)
at System.Security.AccessControl.RegistrySecurity.Persist(SafeRegistryHandle hKey, String keyName)...
Weiß jemand, wie man das zum Laufen bringt? Danke!