的唯一可靠方法似乎是挂接到Windows事件队列和抑制对话框(如各种事情可以获得用户访问权限)。这是我们的辅助类做什么:
void ListenForDialogCreation()
{
// Listen for name change changes across all processes/threads on current desktop...
_WinEventHook = WinAPI.SetWinEventHook(WinAPI.EVENT_OBJECT_CREATE, procDelegate);
}
void StopListeningForDialogCreation()
{
WinAPI.UnhookWinEvent(_WinEventHook);
}
void WinEventProc(IntPtr hWinEventHook, uint eventType, IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime)
{
const uint OBJID_WINDOW = 0;
const uint CHILDID_SELF = 0;
// filter out non-HWND, and things not children of the current application
if (idObject != OBJID_WINDOW || idChild != CHILDID_SELF)
return;
//Get the window class name
StringBuilder ClassName = new StringBuilder(100);
WinAPI.GetClassName(hwnd, ClassName, ClassName.Capacity);
// Send close message to any dialog
if (ClassName.ToString() == "#32770")
{
WinAPI.SendMessage(hwnd, WinAPI.WM.CLOSE, IntPtr.Zero, IntPtr.Zero);
if (OnDialogCancelled != null)
OnDialogCancelled();
}
if (ClassName.ToString() == "#32768")
{
WinAPI.SendMessage(hwnd, WinAPI.WM.CLOSE, IntPtr.Zero, IntPtr.Zero);
if (OnDialogCancelled != null)
OnDialogCancelled();
}
}
public delegate void OnDialogCancelledEvent();
public event OnDialogCancelledEvent OnDialogCancelled;
- #32770是Dialog类
- #32768是弹出菜单
- 的WinAPI的命名空间是我们的PInvoke包装。
如果您不希望阻止所有对话框,您将在添加一些额外的过滤器后添加到该类中。这取决于你需要的安全程度。在$ WORK中,我们需要阻止所有上传和下载。
抑制弹出式菜单是必要的,因为它允许访问帮助应用程序,该应用程序可以链接到microsoft的网站,从而可以启动完整的IE实例。然后他们可以做任何他们想做的事。
让我得到这个海峡......你想允许你的用户访问互联网(这不过是把文件下载到电脑里),你想阻止所有的下载? – Sergio 2009-01-27 12:56:13
@Sergio:我想,Jens想阻止所有文件,这些文件不能直接在webbrowser中显示。 – TcKs 2009-01-27 14:05:41
TcKs是正确的,我想阻止无法显示的所有内容。重点不在于防止下载,而是为了防止任何“保存文件为”对话框显示,以便用户无法访问硬盘。我的应用程序被安装为Windows外壳程序(没有资源管理器,没有开始菜单)。 – 2009-01-29 06:30:10