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

How to Open and Close Internet Explorer from batch file?

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

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

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

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

第一个批处理文件出了什么问题。

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

我不明白您打开和立即关闭 Internet Explorer 的目的是什么?但这里有一个睡眠示例,向您展示它是如何工作的!

@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

如果您想了解更多功能,例如如何启动一个进程以及如何同时终止一个或多个进程,这些进程通过动态菜单与用户输入交互,您应该看看这个 post ==>

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

@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