如何从批处理文件中打开和关闭 Internet Explorer?

Posted

技术标签:

【中文标题】如何从批处理文件中打开和关闭 Internet Explorer?【英文标题】:How to Open and Close Internet Explorer from batch file? 【发布时间】:2015-09-02 08:19:17 【问题描述】:

我有一个批处理文件,它必须启动 Internet Explorer 并打开 www.google.com。当整个页面加载完成时,它应该终止 IE 进程,即关闭该系统中的所有 IE 实例。我的批处理文件有以下两行。

iexplore.exe "www.google.com"
taskkill /IM iexplore.exe /F

但加载后并没有关闭 IE 实例。

如果我有单独的批处理文件,其中只有一行 taskkill /IM iexplore.exe /F。此批处理文件关闭 IE 实例。

First Batch 文件出了什么问题。

P.S 批处理文件在 Internet Explorer 程序文件的文件夹中。

【问题讨论】:

在taskkill之前尝试睡眠 这听起来像XY problem?。为什么要打开一个网页然后立即关闭它? @DavidPostill 只是想尝试一下。它与任何问题或解决方案无关。 【参考方案1】:

我不完全理解您打开和立即关闭 Internet Explorer 的目的?但这里有一个 sleep 的例子,向你展示它是如何工作的!

@echo off
Title Start and Kill Internet Explorer
Mode con cols=75 lines=5 & color 0B
echo(
echo                     Launching Internet Explorer ...
Start "" "%ProgramFiles%\Internet Explorer\iexplore.exe" "www.google.com"
:: Sleep for 20 seconds
Timeout /T 20 /NoBreak>NUL
echo(
echo            Hit any Key to kill all instances of Internet Explorer
Pause>nul
Cls & Color 0C
echo(
echo              Killing Internet Explorer Please wait for a while ...
Taskkill /IM "iexplore.exe" /F
pause

如果您想了解更多功能,例如如何启动一个进程以及如何一次终止一个或多个进程,这些功能与动态菜单与用户输入交互,您应该看看这篇文章 ==> @987654321 @

在没有用户输入确认的情况下尝试这个替代方案:

@echo off
Title Start and Kill Internet Explorer
Mode con cols=75 lines=5 & color 0B
echo(
echo                     Launching Internet Explorer ...
Start "" "%ProgramFiles%\Internet Explorer\iexplore.exe" "www.google.com"
:: Sleep for 10 seconds, you can change the SleepTime variable
set SleepTime=10
Timeout /T %SleepTime% /NoBreak>NUL
Cls & Color 0C
echo(
echo              Killing Internet Explorer Please wait for a while ...
Taskkill /IM "iexplore.exe" /F

【讨论】:

我不需要任何手动帮助。它要求确认。我们可以不提示用户单击任何键吗?

以上是关于如何从批处理文件中打开和关闭 Internet Explorer?的主要内容,如果未能解决你的问题,请参考以下文章

如何使程序仅在使用批处理或 powershell 有 Internet 连接时运行? [关闭]

如何打开8080端口

如何让批处理命令后运行后自动关闭

从批处理文件和/或C#更改LAN设置?

我如何从文件夹中打开mac中的终端[关闭]

用于打开和关闭代理的Windows桌面小部件