Tag: #registration

从Autofac Builder获取所有AsClosedTypesOf注册变体

让我们假设这些类/接口: public interface ICommand { } public class SomeCommand : ICommand { } public interface ICommandHandler where T : ICommand { void Handle(T arg); } public class SomeCommandHandler : ICommandHandler { void Handle(SomeCommand arg){ /* do something */ } } public interface ICommandBus { void RegisterHandler(T t) where T : ICommandHandler; void RegisterHandlerByParam(ICommandHandler t2) where […]

C#Registry SetValue抛出UnauthorizedAccessException

在您尝试使用“快速Google搜索”进行回答之前。 我想指出我已经。 这是情况,我有以下方法尝试修改注册表项值。 我得到的问题是,当执行时,它会抛出一个UnauthorizedAccessException, 即使我已经将密钥打开为可写 。 我以管理员身份运行Visual Studio,甚至尝试使用清单文件制作一个小的.exe,强制它以管理员身份运行,执行代码时没有运气。 密钥已经存在,它不会尝试进入CreateKey方法。 这是代码块。 Path = “S-1-5-21-1644491937-1078145449-682003330-5490\Software\Microsoft\Windows\CurrentVersion\Policies\System” Key = “DisableTaskMgr” NewValue = 1 public OperationResult ModifyKey() { OperationResult result = new OperationResult(); if (!Path.IsNullOrEmptyTrim()) { if (!Key.IsNullOrEmptyTrim()) { try { var key = Microsoft.Win32.Registry.Users.OpenSubKey(Path, true); if (key != null) { key.SetValue(Key, NewValue); key.Close(); } else { result = CreateKey(); […]