当前位置: 移动技术网 > IT编程>脚本编程>VBScript > 利用wscript执行文件[包括可执行exe文件]vbs脚本

利用wscript执行文件[包括可执行exe文件]vbs脚本

2017年12月12日  | 移动技术网IT编程  | 我要评论

异世之光环召唤师txt,候机室情缘,台球风暴

昨天下载并且安装了updater application block后,需要执行一个deploy.vbs的文件,鄙人才疏学浅,这个小问题竟然也花费了我不少心机。
现在把结论共享一下。

首先,我的vbs文件关联已经被“豪杰”夺取了。我双击deploy.vbs就会打开豪杰,比较郁闷。但是我用了打开方式,试了浏览器、cmd,都无济于事。

今天,我想到这个问题后,就有想法去microsoft的news group上去问一问。然后又去了csdn的全文检索。果然很争气,我的关键字只是vbs,执行,就找到了一大堆我想要的东东。了解到用wscript.exe来执行这个文件。

在cmd里敲了wscript.exe deploy.vbs,但是返回错误是  there is no script engine for file extension '.vbs'。这个时候我想到了google。果然搜到了不少有用的信息,其中第一条里我就找到了解决办法。 原因是我的vbs关联已经丢失了,必须显示指定。

cmd中敲入 wscript.exe  //e:vbscript  deploy.vbs。果然成功!!!

 

总结:用wscript.exe 执行类似vbs这类的脚本文件。如果文件关联丢失。可以用//e:vbscript.

 

附上我找到的很有帮助的文章。


一、什么是wsh? 

wsh是windows scripting host(windows脚本主机)的缩略形式。wsh这个概念最早出现于windows 98操作系统,是一个基于32 位  windows 平台、并独立于语言的脚本运行环境。比如:你自己编写了一个脚本文件,如后缀为 .vbs 或 .js 的文件,然后在 windows 下双击 并执行它,这时,系统就会自动调用一个适当的程序来对它进行解释并执行,而这个程序,就是 windows scripting host,程序执行文件名为  wscript.exe (若是在dos命令提示符下,则为 cscript.exe)。 

 

想知道自己的机器上有没有wsh吗?查看一下你的机器里有没有“wscipt.exe”或者“cscript.exe”这两个文件就可以了。如果找到,恭 喜你!你已经安装了wsh。否则,自己手动安装吧: 

在windows 98环境下,wsh是作为操作系统的一个组件自动安装的,如果不慎丢失了这个组件,可以从依次打开“控制面板-->添加/删除程 序--〉windows安装程序--〉附件”,然后将“windows scripting host”前的划上“√”,再确定即可完成wsh组件的安装。 

 

二、脚本语言与wsh的关系 

大家知道,脚本语言(包括javascript和vbscript语言等)经常会被植入网页之中(其中包括 html 页面客户机端和 asp 页面服务器端) 。对于植入 html 页面的脚本,其所需的解析引擎会由 ie 这样的网页浏览器载入;对于植入 asp 页面的脚本,其所需的解析引擎会由 iis( internet information services)提供。而对于出现在 html 和 asp 页面之外的脚本(它们常以独立的文件形式存在),就需要经由 wsh 来 处理了。需要说明的是:wsh 要想正常工作,还要安装ie 3.0 或更高版本的 ie,因为 wsh 在工作时会调用 ie 中的 vbscript 和  javascript 解析引擎。 [未结束][iduba_page]在这些被植于网页的脚本语言中,绝大多数是与网络安全无关的。但也有少数别有用心的好事 者,把一些严重危及网络安全的代码(我们常常称之为“恶意代码”,他们通常都要通过修改注册表达到“恶意”的目的!),混放在正常的 脚本之中,常常让我们防不胜防。但是,如果我们了解一点关于脚本语言的知识,这些“伎俩”都是非常容易识破的。还是让我们从几个简单 的实例开始吧…… 

 

三、wsh应用举例 

wsh可以处理脚本程序,怎样阅读和编写wsh的脚本源文件呢?只要你有一点basic(会vb的编程更好,呵呵)语言的基础,学会看懂wsh脚 本语言的程序并不是一件难事。去c:windowssampleswsh目录以下将看看吧!里面提供了几类经典的脚本例子,而且分别提供了vbscript和 javascript两个版本,我们只要用记事本打开它们并仔细研究就不难学到一些基本的wsh应用。 

 

你只需在记事本中依次输入以下每个实例中的代码,并保存为相应的“*.vbs”文件,双击这个文件,你就可以看到相应的效果了。

 

 

 

q: how do i open script files? trying the above solution makes windows xp throw an error?

a: this is similar to the *.js association problem. some machines seem to, for some reason, lose their *.vbs association. it's not that the files open with dreamweaver or whatever -- it's that the machine just doesn't know how to run them. if you have a scheduled task, "could not run" will appear in the status column.

so, you're a smart person and read through the faq. you find the *.js extension problem, and you try that fix: you run it as "wscript c:\path\to\script.vbs". but that, in turn, produces a pop-up error, this time a "windows scripting host" error: "there is no script engine for file extension '.vbs'." so, for some reason, wscript doesn't even know what to do with *.vbs files.

the solution to this problem is to run the script as:

wscript //e:vbscript c:\path\to\script.vbs

the "//e:vbscript" tells wscript to use the vbscript engine to parse the script. it will then run correctly.

a few alternative solutions, perhaps easier are:

rename it .vbe (vbscript encoded script file). not sure if this is a bad idea, but it seemed to work for some scripts. 
make a new association for vbs. open up my computer, select tools menu-> folder options, and go to the file types tab. there probably isn't a vbs association listed if you have this problem. select new, type in vbs, and hit advanced>>. then, from the pull-down menu, select "vbscript script file". making this selection automatically takes care of the association, along with the //e:vbscript problem. this is probably the "correct" solution... 
this problems usually occurs only on windows xp machines, but the cause is not known. a microsoft kb article on this issue can be found here. thanks goes to bob_2k for writing this faq entry.

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

相关文章:

验证码:
移动技术网