在vbs中WScript.Shell 与 Shell.Application 的不同


本文主要对比,VBScript 中 CreateObject("WScript.Shell") 和 CreateObject("Shell.Application") 之间,有什么不同。


代码上的不同:

这里,就以打开Chrome浏览器的方法,为实例,来说明使用上的不同!


url = "www.google.com"

'第一种方法
set oShell = WScript.CreateObject("WScript.Shell")
oShell.run "chrome.exe"
WScript.sleep 1000
oShell.sendkeys url
WScript.sleep 1000
oShell.sendkeys "{ENTER}"

'第二种方法
Set oShell = CreateObject("shell.application")
oShell.ShellExecute "chrome", url,"","",1

'如果Chrome是默认浏览器的话
set oShell = CreateObject("WScript.Shell")
oShell.run url

所以,从这个实例中,可以看出 oShell.ShellExecute 方法,更加灵活。

参考阅读:

  1. wshom.ocx_百度百科
  2. WScript.Shell vs Shell.Application
  3. Diff between wscript.shell and shell.application
  4. Shell.ShellExecute method | Microsoft Docs
  5. shell32.dll Windows process - What is it?
  6. Opening browser on a variable page using vbscript - Stack Overflow

出处:https://www.cnblogs.com/bitssea/p/12590701.html

VBS