Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google chrome 从命令行仅杀死一次chrome实例_Google Chrome_Batch File_Taskkill - Fatal编程技术网

Google chrome 从命令行仅杀死一次chrome实例

Google chrome 从命令行仅杀死一次chrome实例,google-chrome,batch-file,taskkill,Google Chrome,Batch File,Taskkill,我有一个批处理文件,可以在Chrome中打开一个运行特定功能的网页 start http://www.example.com/cgi/myprogram.exe 这个过程运行得很快,然后我想自动关闭浏览器窗口。我不想使用taskkill/IM chrome.exe,因为chrome有许多服务在“chrome.exe”下运行,我只想杀死任务管理器的应用程序标签上显示的服务,而不是进程标签上显示的服务 这可能吗?要取消新选项卡,可以使用以下方法: @echo off setlocal Enable

我有一个批处理文件,可以在Chrome中打开一个运行特定功能的网页

start http://www.example.com/cgi/myprogram.exe
这个过程运行得很快,然后我想自动关闭浏览器窗口。我不想使用
taskkill/IM chrome.exe
,因为chrome有许多服务在
“chrome.exe”
下运行,我只想杀死任务管理器的应用程序标签上显示的服务,而不是进程标签上显示的服务


这可能吗?

要取消新选项卡,可以使用以下方法:

@echo off
setlocal EnableDelayedExpansion
set "newPIDlist="
set "oldPIDlist=p"
::find old PIDs
for /f "TOKENS=1" %%a in ('wmic PROCESS where "Name='chrome.exe'" get ProcessID ^| findstr [0-9]') do (set "oldPIDlist=!oldPIDlist!%%ap")
::start your site here
start http://www.example.com/cgi/myprogram.exe
::find new PIDs
for /f "TOKENS=1" %%a in ('wmic PROCESS where "Name='chrome.exe'" get ProcessID ^| findstr [0-9]') do (
if "!oldPIDlist:p%%ap=zz!"=="%oldPIDlist%" (set "newPIDlist=/PID %%a !newPIDlist!")
)
echo %newPIDlist%
::wait for page to load
timeout /t 5 /nobreak >nul
taskkill /f %newPIDlist% /T > NUL 2>&1

但是,请注意,这不会关闭选项卡,它只会终止选项卡的进程,导致弹出错误消息。如前所述,从命令行关闭单个google chrome选项卡是不可能的。

相关:我认为每个进程有时也可能有多个选项卡,因此这可能会产生意想不到的后果。你是对的,但据我所知,这是获得正确选项卡的唯一原因,例如,
wmic进程调用create
不会从谷歌浏览器返回PID。