我的应用程序需要模拟一个服务帐户,我通过对LogonUser
. 但是,.Net 库中的随机组件似乎会尝试访问该帐户无权访问的注册表项,从而导致 aSecurityException
被抛出。
具体来说,当我加载 a 时LinkLabel
,它会在尝试确定 IE 中的默认超链接颜色时崩溃:
System.Security.SecurityException:不允许请求的注册表访问。 在 System.ThrowHelper.ThrowSecurityException(ExceptionResource 资源) 在 Microsoft.Win32.RegistryKey.OpenSubKey(字符串名称,布尔可写) 在 Microsoft.Win32.RegistryKey.OpenSubKey(字符串名称) 在 System.Windows.Forms.LinkUtilities.GetIEColor(字符串名称) 在 System.Windows.Forms.LinkUtilities.get_IELinkColor() 在 System.Windows.Forms.LinkLabel.get_LinkColor() 在 System.Windows.Forms.LinkLabel.OnPaint(PaintEventArgs e) 在 System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e,Int16 层,布尔 disposeEventArgs) 在 System.Windows.Forms.Control.WmPaint(消息和 m) 在 System.Windows.Forms.Control.WndProc(消息和 m) 在 System.Windows.Forms.Label.WndProc(消息和 m) 在 System.Windows.Forms.LinkLabel.WndProc(消息和消息) 在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(消息& m) 在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(消息和 m) 在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam) 失败的程序集区域是:MyComputer
不,设置默认颜色没有帮助。
我发现这个线程有完全相同的问题,但恐怕我不明白解决方案:
加载的注册表配置单元
LoadUserProfile
存储在 HKU 下,HKCU 仍然是交互式登录用户的配置单元(由 winlogon.exe 加载)。因此,如果您需要访问新加载的配置单元,您需要:
- 设置Regkey
为Registry.Users
- 使用您正在模拟的用户帐户的字符串 SID 打开子项。
有谁知道任何解决方法?