📅  最后修改于: 2023-12-03 15:38:27.969000             🧑  作者: Mango
在 VBScript 中打开 Chrome 可以通过 Shell 对象来实现。执行以下步骤:
Set WshShell = WScript.CreateObject("WScript.Shell")
chromeKey = "HKLM\SOFTWARE\Google\Chrome\Extensions"
Set regObj = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
regObj.EnumKey HKEY_LOCAL_MACHINE, chromeKey, extKeys
For Each keyName In extKeys
If InStr(keyName, ".") > 0 Then
installKey = chromeKey & "\" & keyName & "\path"
regObj.GetStringValue HKEY_LOCAL_MACHINE, installKey, "", installPath
If InStr(1, installPath, "chrome.exe", vbTextCompare) Then
Exit For
End If
End If
Next
WshShell.Run """" & installPath & """", 1, False
完整代码如下:
Set WshShell = WScript.CreateObject("WScript.Shell")
chromeKey = "HKLM\SOFTWARE\Google\Chrome\Extensions"
Set regObj = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
regObj.EnumKey HKEY_LOCAL_MACHINE, chromeKey, extKeys
For Each keyName In extKeys
If InStr(keyName, ".") > 0 Then
installKey = chromeKey & "\" & keyName & "\path"
regObj.GetStringValue HKEY_LOCAL_MACHINE, installKey, "", installPath
If InStr(1, installPath, "chrome.exe", vbTextCompare) Then
Exit For
End If
End If
Next
WshShell.Run """" & installPath & """", 1, False
通过以上步骤,就可以在 VBScript 中打开 Chrome 了。