C# 自定义操作检查IE是否正在运行,然后在运行时将其关闭

C# 自定义操作检查IE是否正在运行,然后在运行时将其关闭,c#,internet-explorer,action,C#,Internet Explorer,Action,我正在尝试为IE创建一个插件安装程序,所以在继续安装之前,IE进程必须被终止。但是当我在IE进程上执行kill()方法时,我得到了“拒绝访问”错误 最好的方法是什么 我的安装程序代码: protected override void OnBeforeInstall(System.Collections.IDictionary savedState) { if (LaunchOnBeforeInstall()) { foreach (var process in P

我正在尝试为IE创建一个插件安装程序,所以在继续安装之前,IE进程必须被终止。但是当我在IE进程上执行
kill()
方法时,我得到了“拒绝访问”错误

最好的方法是什么

我的安装程序代码:

protected override void OnBeforeInstall(System.Collections.IDictionary savedState)
{
    if (LaunchOnBeforeInstall())
    {
        foreach (var process in Process.GetProcesses())
        {
            if (!process.ProcessName.StartsWith("iexplore"))
            {
                process.Kill();
            }
        }
    base.OnBeforeInstall(savedState);
    }
    else
    {
        throw new Exception("You cancelled the installation.");
    }
}

public bool LaunchOnBeforeInstall()
{
    var result = MessageBox.Show("All instance of IE will be close", "Warning", MessageBoxButtons.OKCancel,
    MessageBoxIcon.Question);
    return result != DialogResult.Cancel;
}
您的问题:

if (!process.ProcessName.StartsWith("iexplore"))
{
process.Kill();
}

你的程序正在试图杀死除Internet Explorer之外的所有东西

你使用的是受限帐户吗?另外值得注意的是,IE的新版本使用了线程选项卡,每个选项卡都显示为一个进程,因此您必须杀死所有实例。