2017-03-09 185 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