开发者

Can "AddInProcess.exe has stopped working" be suppressed?

I am attempting to sandbox potentially malicious code by executing it within a MAF plugin launched in its own process:

    var x = token.Activate<Ix>(new AddInProcess(), AddInSecurityLevel.Internet);

This seems to work well except that when handling a StackOverflowException a dialog is shown: "AddInProcess.exe has stopped working". This makes it very hard to test

    [TestMethod]
    public void TestStackOverflow() {
        var host = new Host(Environment.CurrentDirectory
            + "/../../../build/pipeline");
        host.Run("foo");
        host.Tick();
        Thread.Sleep(1000);
        host.Monitors.Count.Should().Be(0);
        host.Shutdown();
    }

If I click the "close" button before the Sleep expires, the test succeeds, otherwise it fails. This indicates that the process does not exit until the "close" button is pressed. Given I am expecting the process to terminate, how can I make sure it does so without raising this dialog? I have tried setting my OS to "never check for solutions" but the dialog still comes up. Setting it to "automatically check for soluti开发者_高级运维ons" avoids the dialog but takes up to ten seconds which is not desirable... and I would rather avoid an OS setting.

Can "AddInProcess.exe has stopped working" be suppressed?


You can call SetErrorMode somewhere inside the addin process like so:

    [Flags]
    enum ErrorModes : uint {
        SYSTEM_DEFAULT = 0x0,
        SEM_FAILCRITICALERRORS = 0x0001,
        SEM_NOALIGNMENTFAULTEXCEPT = 0x0004,
        SEM_NOGPFAULTERRORBOX = 0x0002,
        SEM_NOOPENFILEERRORBOX = 0x8000
    }

    [DllImport( "kernel32.dll" )]
    static extern ErrorModes SetErrorMode( ErrorModes uMode );

    var em = SetErrorMode( 0 );
    SetErrorMode( em | ErrorModes.SEM_NOGPFAULTERRORBOX | ErrorModes.SEM_FAILCRITICALERRORS | ErrorModes.SEM_NOOPENFILEERRORBOX );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜