2017-03-09 106 views
0

我想创建这样的:VBS关闭所有Chrome标签

strComputer = "." 
Set objWMIService = GetObject("winmgmts:" _ 
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 

Set colProcessList = objWMIService.ExecQuery _ 
("Select * from Win32_Process Where Name = 'Chrome.exe'") 

Set oShell = CreateObject("WScript.Shell") 
For Each objProcess in colProcessList 
oShell.Run "taskkill /im chrome.exe", , True 
Next 

Dim iURL 
Dim objShell 

iURL = "www.google.com.au" 

set objShell = CreateObject("Shell.Application") 
objShell.ShellExecute "chrome.exe", iURL, "", "", 1 

代码工作,但如果有太多的镀铬选项卡中打开,它并没有关闭所有标签。在关闭标签中有时还会出现一条错误消息。

回答

0

一种方法是在incognito模式下打开Chrome,以便您看不到Restore Session错误。

Dim objExec, objShell, iURL 

Set objShell = CreateObject("WScript.Shell") 
Set objExec = objShell.Exec("tasklist /fi " & Chr(34) & "imagename eq chrome.exe" & Chr(34)) 
If Not InStr(1, objExec.StdOut.ReadAll(), "INFO: No tasks", vbTextCompare) Then 
    objShell.Run "taskkill /f /t /im chrome.exe", 0, True 
End If 

iURL = "www.google.com.au" 
objShell.Run "chrome.exe -incognito " & iURL 

Set objExec = Nothing : Set objShell = Nothing 

WScript.Quit 
+0

谢谢,我感谢您的帮助! – theperfectcucumber