我正在用 C# 开发 Internet Explorer 浏览器帮助程序对象 (BHO)。此 BHO 检测用户导航到的 URL,然后自动填充用户名和密码。
BHO 与作为服务运行的进程通信。通信通过命名管道进行。
当保护模式关闭时,通信工作正常。但是,当保护模式打开时,这不起作用。如果我以管理员身份运行 iexplore.exe,那么它可以工作。
在保护模式下,我收到拒绝访问消息。
在阅读完这篇文章后,我意识到管道访问被拒绝,因为 IE 在低完整性范围内运行。
我已经阅读了以下文章。了解和在保护模式下工作 Internet Explorer http://msdn.microsoft.com/en-us/library/bb250462.aspx
b.在创建管道资源之前还经历了许多设置安全信息的建议,以允许较低完整性的进程使用它。然而,这些对我来说并没有多大用处。我仍然得到同样的错误。
我目前唯一的解决方法是通过套接字进行通信。我验证了这种方法有效。
我更喜欢使用命名管道方法。
以下是我在打开管道之前设置安全上下文的源代码
服务端代码:
PipeSecurity security = new PipeSecurity();
security.AddAccessRule(new PipeAccessRule(
new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null), // @"Users"
PipeAccessRights.ReadWrite,
System.Security.AccessControl.AccessControlType.Allow
));
var currentUser = WindowsIdentity.GetCurrent().Name;
security.AddAccessRule(new PipeAccessRule(currentUser, PipeAccessRights.FullControl, System.Security.AccessControl.AccessControlType.Allow));
NamedPipeServerStream stream;
stream = new NamedPipeServerStream(
CommandPipeName,
PipeDirection.InOut, MAX_PIPE_INSTANCE,
PipeTransmissionMode.Message, PipeOptions.WriteThrough,
EPHelperCommandPipeServerConsts.MaxPipeRequestLength,
EPHelperCommandPipeServerConsts.MaxPipeResponseLength,
security
);
do
{
n++;
isListening = true;
stream.WaitForConnection();
isListening = false;
var cs = stream;
stream = new NamedPipeServerStream(
CommandPipeName,
PipeDirection.InOut, MAX_PIPE_INSTANCE,
PipeTransmissionMode.Message, PipeOptions.WriteThrough,
EPHelperCommandPipeServerConsts.MaxPipeRequestLength,
EPHelperCommandPipeServerConsts.MaxPipeResponseLength,
security
);
// some code
} while (true);
有什么我想念的吗?
谢谢。