WScript.Shell And Shell.Application It’s different


In this paper, the main comparison, VBScript create object(“ WScript.Shell “) and CreateObject (” Shell.Application There is no difference between them.

Code differences:

The code is as follows:

'the first way
Set oShell = CreateObject("WScript.Shell")
oShell.Run "xxxx.exe"

'the second way
Set oShell = CreateObject("shell.application")
oShell..ShellExecute "xxxx.exe", "", "", "", 1

Here we mainly record the difference between the two seemingly similar methods

  1. First of all, they come from two completely different objects, or two different COM objects, that is to say, they come from two different DLL files
    1. In the first method, the object is derived from the wshom.ocx file
      1. It’s the proid of the WSH shell
      2. The WSH shell object is stored in the wshom.ocx In the file
    2. In the second method, the object is derived from the shell32.dll file
  2. Moreover, these two different objects use different ways to accomplish different tasks

Differences in use:

Here, take the method of opening Chrome browser as an example to illustrate the difference in use!

url = ""

'the first way
set oShell = WScript.CreateObject("WScript.Shell") "chrome.exe"
WScript.sleep 1000
oShell.sendkeys url
WScript.sleep 1000
oShell.sendkeys "{ENTER}"

'the second way
Set oShell = CreateObject("shell.application")
oShell.ShellExecute "chrome", url,"","",1

'if Chrome is the default browser
set oShell = CreateObject("WScript.Shell") url

So, from this example, we can see that oShell.ShellExecute Method, more flexible.

Reference reading:

  1. wshom.ocx_ Baidu Encyclopedia
  2. WScript.Shell vs Shell.Application
  3. Diff between 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