Joe
Wed Jan 21 09:55:32 CST 2004
Hi,
To add a bit to Alex's post ...
"Ed Bachmann" <ed_bachmann@unc.edu> wrote in message
news:400e94b3$1_3@news.unc.edu...
| Can anyone tell me why Wscript.Echo, Wscript.Quit, and Wscript.Scriptname
| don't work in Windows Script Components?
|
| Thanks,
| Ed
The immediate WScript object methods and properties are designed to work
only where WSH is the host. WSH is the host only where wscript.exe and
cscript.exe are run directly. Otherwise, each scripting host that allows
VBS/JS accessess the various WSH DLL or OCX files, as that host is coded.
WSC is an XML scripting host. MS placed the immediate WScript host methods
and properties (only) in the WSH EXE files, themselves, so they are not
accessible from other scripting hosts. (Credit Tom Lavedas for a post with
this info.) By comparison, the fundamental WScript.Shell object and the Err
object are exposed through DLL or OCX files, and are available in other
hosts, when not suppressed for security reasons. MS apparently believes
that the immediate WScript methods and properties present a basic conflict
or security hazard with other hosts.
Here's some script that I use in my WSC library file for passing the WScript
object into a WSC file and setting a flag for internal use and verification
(using "oWsc" as the variable holding the declared WSC file object
instance):
From the calling VBS file script:
---
oWsc.wsh= wscript
---
In the WSC file:
---
...
<property name="Wsh" put="putWsh" />
...
' global level code
dim qWsh, oWsh
set oWsh= nothing
...
function putWsh (vo)
if isobject(vo) then
set oWsh= vo
on error resume next
oWsh.sleep 10: qWsh= (err=0)
on error goto 0
if NOT qWsh then set oWsh= nothing
end if
end function
---
Wsh object scope inside the WSC is, of course, limited to the duration of
the calling WSH-hosted VBS script, but this is generally not a problem,
since the WSC object scope, itself, will normally also be limited to the
duration of the calling WSH-hosted VBS script.
Joe Earnest
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (
http://www.grisoft.com).
Version: 6.0.564 / Virus Database: 356 - Release Date: 01-19-04