从 PowerShell 脚本启动 Internet Explorer [英] Launching Internet Explorer from a PowerShell script

查看:118
本文介绍了从 PowerShell 脚本启动 Internet Explorer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将一些 PS 代码放在一起,在更大的 PS 脚本中执行以下操作:

I’ve put together some PS code that does the following inside of a larger PS script:

  • 测试 IE 进程是否已经在运行
  • 如果 IE 尚未运行,请启动一个新进程,在该进程中打开站点 1,然后在该进程的前台选项卡中打开站点 2
  • 使 IE 进程全屏

  • Test if an IE process is already running
  • If IE is not already running, start a new process, open site one in that process then open site two in the foreground tab of that process
  • Make the IE process full screen

If (-Not (Get-Process IExplore -ErrorAction SilentlyContinue))
    {
    $navOpenInForegroundTab = 0x10000;
    $ie = New-Object -Com InternetExplorer.Application
    $ie.Visible = $True;
    $ie.Navigate2("https://stackoverflow.com");
    $ie.Navigate2("http://superuser.com", $navOpenInForegroundTab);

$sw = @'
[DllImport("user32.dll")]
public static extern int ShowWindow(int hwnd, int nCmdShow);
'@

    $type = Add-Type -Name ShowWindow2 -MemberDefinition $sw -Language CSharpVersion3 -Namespace Utils -PassThru
    $type::ShowWindow($ie.hwnd, 3) # 3 = maximize 
    }

似乎一切正常,只是在此代码运行后,它在 PowerShell 窗口中显示数字 24(我正在从命令行启动 PS).谁能告诉我为什么当我运行上面的代码时显示 24 并且可以阻止它显示?

Everything seems to work fine, except that after this code runs, it shows the number 24 in the PowerShell window (I am launching PS from the command line). Can anyone tell me why 24 is being displayed when I run the above code and is it possible to stop it from being displayed?

推荐答案

这是 ShowWindow 函数的返回值.要忽略结果,请使用:

This is the return value from the ShowWindow function. To ignore the result, use:

$type::ShowWindow($ie.hwnd, 3) | out-null

这篇关于从 PowerShell 脚本启动 Internet Explorer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆