当前位置: 移动技术网 > 科技>操作系统>windows > WScript.Shell 与 Shell.Application 的不同

WScript.Shell 与 Shell.Application 的不同

2020年03月29日  | 移动技术网科技  | 我要评论

叶丽倩,凤香阁,行尸走肉第三季下载

本文主要对比,vbscript 中 createobject("wscript.shell") 和 createobject("shell.application") 之间,有什么不同。


代码上的不同:

代码如下:

'第一种方法
set oshell = createobject("wscript.shell")
oshell.run "xxxx.exe"

'第二种方法
set oshell = createobject("shell.application")
oshell..shellexecute "xxxx.exe", "", "", "", 1

这里主要记录下,两种看似类似的方法,到底有什么不同:

  1. 首先它俩,来自于完全不同的两个对象(object),或者说两个不同的 com object,也就是说来自于两个不同的 dll 文件
    1. 第一种方法下,使用的 object,源自于 wshom.ocx 文件
      1. wscript.shell 是 wshshell 的 proid (programmatic identifier)
      2. 而,这个 wshshell 对象,则存放在 wshom.ocx 文件中
    2. 第二种方法下,使用的 object,源自于 shell32.dll 文件
  2. 再者,这两个不同 object,是用不同的途径,去完成不同的任务

使用上的不同:

这里,就以打开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. shell.shellexecute method | microsoft docs
  2. shell32.dll windows process - what is it?
  3. opening browser on a variable page using vbscript - stack overflow



如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网