2

我正在尝试从我们的 WPF 应用程序以另一个用户身份启动 Internet Explorer,这样当我们的用户访问(内部)网站时,他们会通过集成 Windows 身份验证静默进行身份验证。

我们不想以其他用户身份启动 iexplore.exe,因为当您在计算机上首次启动进程并且它首次尝试设置 IE7/8 时会出现奇怪的部署/环境问题。不过,如果您有一个解决方案来解决如何将每台机器上的每个 IE 安装程序静音,我很想听听。

回到我的预期问题。我可以使用命令提示符获得我想要的确切 IE 模拟行为* runas(感谢https://serverfault.com/questions/70376/runas-domain-account-still-asks-for-password):

c:\> runas /noprofile /netonly /user:MyDomain\MyUser iexplore.exe

runas*注意:由于多种原因,我不能用于我们的 WPF 应用程序,但最终结果是我想要的。

无论如何,我想要执行runas /noprofile /netonly iexplore.exe.

我已经完成了 P/Invoke 的一半CreateProcessWithLogonW。这就是我所拥有的:

uint LOGON_NETCREDENTIALS_ONLY = 2;
var lpStartupInfo = new CreateProcessWithLogonW_PInvoke.STARTUPINFO();
CreateProcessWithLogonW_PInvoke.PROCESS_INFORMATION processInformation;

CreateProcessWithLogonW_PInvoke.CreateProcessWithLogonW(
                userName,
                domain,
                pw,
                LOGON_NETCREDENTIALS_ONLY,
                null,
                commandLine,
                0,
                null,
                null,
                ref lpStartupInfo,
                out processInformation);

这成功启动了 Internet Explorer,但似乎根本没有模拟用户。我可以通过 runas 命令模拟用户,所以我 98% 确定身份验证失败不是 IE/区域/密码/IIS 设置,这只是我在调用CreateProcessWithLogonW().

我注意到的一件事是,该runas /netonly命令仅在我添加/noprofile开关时才有效,这让我很困惑。我不知道如何通过 C# 中的 P/Invoke 设置此开关的等效项。

任何一种解决方案都可以提供帮助(解决“我第一次启动 IE 时运行向导”的问题,或者找到我缺少的怪异 P/Invoke 设置)。

4

2 回答 2

4

好的,我非常非常接近。神奇的修复是添加-noframemerging到 iexplore.exe 调用,它......老实说,我不确定它做了什么,它使用了“进程框架”这个短语,这很棒,也许对你来说意味着什么。

无论如何,这似乎得到了解决。

var arguments = "-noframemerging " + url;
var pathToIExploreExe = GetFullPathToIExploreExe();
var commandLine = string.Format("\"{0}\" {1}", pathToIExploreExe, arguments);

uint LOGON_NETCREDENTIALS_ONLY = 2;
var lpStartupInfo = new CreateProcessWithLogonW_PInvoke.STARTUPINFO();
CreateProcessWithLogonW_PInvoke.PROCESS_INFORMATION processInformation;

CreateProcessWithLogonW_PInvoke.CreateProcessWithLogonW(
            userName,
            domain,
            pw,
            LOGON_NETCREDENTIALS_ONLY,
            null,
            commandLine,
            0,
            null,
            null,
            ref lpStartupInfo,
            out processInformation);
于 2012-08-22T21:06:23.757 回答
0

CreateProcessWithLogonW要求必须允许指定的用户帐户以交互方式登录。会不会是个问题?如果可行,请尝试CreateProcessAsUser 函数

于 2012-08-22T00:48:03.690 回答