返回列表 发帖

vbs脚本文件执行

昨天下载并且安装了Updater Application Block后,需要执行一个Deploy.vbs的文件,鄙人才疏学浅,这个小问题竟然也花费了我不少心机。
0 D) M9 x9 x$ G5 W+ Z7 G# Q' s现在把结论共享一下。& Z( J% [% w, ?7 L7 I1 n+ W* g
2 A& l. q% |; z! {( F" C
首先,我的vbs文件关联已经被“豪杰”夺取了。我双击Deploy.vbs就会打开豪杰,比较郁闷。但是我用了打开方式,试了浏览器、cmd,都无济于事。+ m7 j6 a. Z5 y" Z
/ T) a+ f. r0 K
今天,我想到这个问题后,就有想法去Microsoft的News Group上去问一问。然后又去了CSDN的全文检索。果然很争气,我的关键字只是vbs,执行,就找到了一大堆我想要的东东。了解到用wscript.exe来执行这个文件。$ w- Z" @) i4 i! U6 m3 P

: c# I/ ^# v& _' }) I在cmd里敲了wscript.exe Deploy.vbs,但是返回错误是  There is no script engine for fileextension '.vbs'。这个时候我想到了google。果然搜到了不少有用的信息,其中第一条里我就找到了解决办法。原因是我的vbs关联已经丢失了,必须显示指定。
# Y( N0 @0 ~3 O
* e& W  r# J& {# v# M( d5 {( V9 a! fcmd中敲入 wscript.exe  //e:vbscript  Deploy.vbs。果然成功!!!8 u& {" y' G: Z/ u; y- W7 x
4 `8 ~. ]2 J7 T9 \5 ^2 R) r

9 [% @/ H4 n" i9 `1 Z* F& l
4 `/ ^: R/ |- N" o! Y总结:用wscript.exe 执行类似vbs这类的脚本文件。如果文件关联丢失。可以用//e:vbscript.
8 w! g3 F# n* E7 ^! {2 d/ b9 g7 o; A
8 S& Q" q  @' c8 n4 D% H3 v* j
6 |' G, ^) c& E' _& Y# |
1 g" ]6 u1 j' D# _附上我找到的很有帮助的文章。
8 N5 S; v6 e3 P, M: w6 S- S* k* u4 d* o! x- s( n2 Y7 h: m* f

* n, K  n' F! ?+ @- ]# L/ E+ L+ v& {4 K3 z
一、什么是WSH?
4 L5 U+ o3 g. U9 B. r2 h% ^
( |/ u% z. X. e  WSH是Windows Scripting Host(Windows脚本主机)的缩略形式。WSH这个概念最早出现于Windows98操作系统,是一个基于32 位  Windows 平台、并独立于语言的脚本运行环境。比如:你自己编写了一个脚本文件,如后缀为 .vbs 或.js 的文件,然后在 Windows 下双击 并执行它,这时,系统就会自动调用一个适当的程序来对它进行解释并执行,而这个程序,就是Windows Scripting Host,程序执行文件名为  Wscript.exe (若是在DOS命令提示符下,则为Cscript.exe)。
9 I; N+ @0 u# z! E- W1 n% A! P% ~6 A1 o* R7 l- L. q
   # [0 u5 o: |8 C8 N& D# F
: B7 j6 x9 p. W; J* w
  想知道自己的机器上有没有WSH吗?查看一下你的机器里有没有“Wscipt.exe”或者“Cscript.exe”这两个文件就可以了。如果找到,恭 喜你!你已经安装了WSH。否则,自己手动安装吧:   d$ C0 ^' S2 ~. t
2 T5 K  N+ S: G) h9 l) S
  在Windows98环境下,WSH是作为操作系统的一个组件自动安装的,如果不慎丢失了这个组件,可以从依次打开“控制面板-->添加/删除程序--〉Windows安装程序--〉附件”,然后将“Windows ScriptingHost”前的划上“√”,再确定即可完成WSH组件的安装。 " N9 L1 }' c$ V* r
6 z) J4 L  I' w- \4 A
  
: c5 e9 ?& q+ M8 g8 i# @! m% z7 I" c  y
  二、脚本语言与WSH的关系 : }! W! H" M. m9 H% s
1 e, g9 c. u- _$ a# J1 k& P* ~
  大家知道,脚本语言(包括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]在这些被植于网页的脚本语言中,绝大多数是与网络安全无关的。但也有少数别有用心的好事者,把一些严重危及网络安全的代码(我们常常称之为“恶意代码”,他们通常都要通过修改注册表达到“恶意”的目的!),混放在正常的脚本之中,常常让我们防不胜防。但是,如果我们了解一点关于脚本语言的知识,这些“伎俩”都是非常容易识破的。还是让我们从几个简单 的实例开始吧……
. H6 m; K3 \$ A$ V, ]
4 J& h7 H# G) G  
5 f# N+ @+ W: M: S% p- Z+ F3 V6 j# x8 e: O' R, c
  三、WSH应用举例 $ y6 W/ \9 s" V7 S: ?
  V# \/ q/ K) M; J( a2 I
  WSH可以处理脚本程序,怎样阅读和编写WSH的脚本源文件呢?只要你有一点Basic(会VB的编程更好,呵呵)语言的基础,学会看懂WSH脚本语言的程序并不是一件难事。去C:WINDOWSSAMPLESWSH目录以下将看看吧!里面提供了几类经典的脚本例子,而且分别提供了VBScript和 javascript两个版本,我们只要用记事本打开它们并仔细研究就不难学到一些基本的WSH应用。 ! y8 c, M1 T9 s

! ~) @, M- s5 s% z, K  
; P& |3 f( a9 j) X% L1 c( N1 K9 h0 r- u6 `+ }8 `
  你只需在记事本中依次输入以下每个实例中的代码,并保存为相应的“*.vbs”文件,双击这个文件,你就可以看到相应的效果了。: F, c4 x& c6 ?+ S& h6 [* H

3 y; \+ V2 g  v' f9 w " \) t% w& h, @7 A+ W
6 I$ M' @7 l' K
- o  e- f/ Z9 y  S' n* \

; J# _9 G4 ~% `4 E, e) ?  k% p+ ^
- m  Y5 a3 {6 K$ ]* R
$ f/ p# y$ I' @# c/ VQ: How do I open script files? Trying the above solution makes Windows XP throw an error?
1 W8 a7 y6 \; A) k
  @% @! z" t8 G/ ~+ o0 tA:This is similar to the *.js association problem. Some machines seem to,for some reason, lose their *.vbs association. It's not that the filesopen with dreamweaver or whatever -- it's that the machine just doesn'tknow how to run them. If you have a scheduled task, "Could not run"will appear in the status column.
# E* u  |9 y9 w, v, M$ P' s1 y! u2 @/ |- ~  ~1 n. q( g9 {+ ~8 X
So, you're a smart person andread through the FAQ. You find the *.js extension problem, and you trythat fix: you run it as "wscript c:\path\to cript.vbs". But that, inturn, produces a pop-up error, this time a "Windows Scripting Host"error: "There is no script engine for file extension '.vbs'." So, forsome reason, wscript doesn't even know what to do with *.vbs files.5 S$ W& |7 w0 O! }" B  y/ K; e- T
* {+ f- A. L- e0 O( Y) _4 A5 S1 f
The solution to this problem is to run the script as:
3 k1 q+ ?( S' N( j& W$ q* r$ E; G- V. z( X& @2 a; {9 J
wscript //e:vbscript c:\path\to cript.vbs) Y( G: F: J( D# c) A1 T

+ ~+ I: o; c3 _' @' t5 I6 I4 zThe "//e:vbscript" tells wscript to use the vbscript engine to parse the script. It will then run correctly.! T1 G9 g5 q* d; V

1 f6 {! k# G% I9 M% g% `: JA few alternative solutions, perhaps easier are:# @0 a$ o5 X" i" _( N" D1 [, U" z
Renameit .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 tothe File Types tab. There probably isn't a VBS association listed ifyou have this problem. Select New, type in VBS, and hitAdvanced>>. Then, from the pull-down menu, select "VBScriptScript File". Making this selection automatically takes care of theassociation, along with the //e:vbscript problem. This is probably the"correct" solution...
- C2 Q- f0 u, b: ~+ WThis problems usually occurs only on WindowsXP machines, but the cause is not known. A Microsoft KB article on thisissue can be found here. Thanks goes to Bob_2k for writing this FAQentry.

返回列表
【捌玖网络】已经运行: