When I double-click on the following file saved
as "c:\test.vbs" it works:

Dim wsh
Set wsh = WScript.CreateObject("WScript.Shell")
Wsh.Run("C:\testfile.exe")

When I double-click on the following file saved
as "c:\test.htm", I get RunTime Error "Line 4 Error:
Object required: 'WScript'". Except for the HTML and
SCRIPT lines, the files are identical (I copied and
pasted the code from one to the other).

<HTML>
<SCRIPT LANGUAGE="vbscript" defer>
Dim wsh
Set wsh = WScript.CreateObject("WScript.Shell")
Wsh.Run("C:\testfile.exe")
</SCRIPT>
</HTML>

Why does it work as a .vbs file and not a .htm file?

Thanks in advance.

Re: WScript.Shell works as .vbs file, doesn't work as .htm file by Joe

Joe
Mon Dec 01 18:29:03 CST 2003

Hi,

"Ed White" <ewhite2142@hotmail.com> wrote in message
news:05d701c3b867$0a87cc80$a101280a@phx.gbl...
| When I double-click on the following file saved
| as "c:\test.vbs" it works:
|
| Dim wsh
| Set wsh = WScript.CreateObject("WScript.Shell")
| Wsh.Run("C:\testfile.exe")
|
| When I double-click on the following file saved
| as "c:\test.htm", I get RunTime Error "Line 4 Error:
| Object required: 'WScript'". Except for the HTML and
| SCRIPT lines, the files are identical (I copied and
| pasted the code from one to the other).
|
| <HTML>
| <SCRIPT LANGUAGE="vbscript" defer>
| Dim wsh
| Set wsh = WScript.CreateObject("WScript.Shell")
| Wsh.Run("C:\testfile.exe")
| </SCRIPT>
| </HTML>
|
| Why does it work as a .vbs file and not a .htm file?

The WScript object is only available when WSH-hosted (i.e., running directly
under wscript.exe or cscript.exe). By design, it is not available in any of
the HTML-hosted or XML-hosted formats, including HTAs (MSHTA-hosted) and
WSCs (although it can be handed into a WSC object from the the calling
script through an exposed property). The secondary WSH objects (e.g.,
WScript.Shell) and other primary objects (e.g., Err) are located in files
other than the WSH exe files and remian accessible by design. Only the
immediate WScript methods and properties are unavailable (most notably
including Sleep).

The WSH-hosted Script.CreateObject method and the standard WSH language
intrinsic CreateObject function are quite similar, except for the former's
ability to automatically sink events to procedures.

Use CreateObject instead of WScript.CreateObject.

Joe Earnest



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.521 / Virus Database: 319 - Release Date: 09-23-03



Re: WScript.Shell works as .vbs file, doesn't work as .htm file by Joe

Joe
Mon Dec 01 18:41:08 CST 2003

Hi,

This may be a duplicate, but I got an error message on my end when I sent it
the first time, so ...

"Ed White" <ewhite2142@hotmail.com> wrote in message
news:05d701c3b867$0a87cc80$a101280a@phx.gbl...
| When I double-click on the following file saved
| as "c:\test.vbs" it works:
|
| Dim wsh
| Set wsh = WScript.CreateObject("WScript.Shell")
| Wsh.Run("C:\testfile.exe")
|
| When I double-click on the following file saved
| as "c:\test.htm", I get RunTime Error "Line 4 Error:
| Object required: 'WScript'". Except for the HTML and
| SCRIPT lines, the files are identical (I copied and
| pasted the code from one to the other).
|
| <HTML>
| <SCRIPT LANGUAGE="vbscript" defer>
| Dim wsh
| Set wsh = WScript.CreateObject("WScript.Shell")
| Wsh.Run("C:\testfile.exe")
| </SCRIPT>
| </HTML>
|
| Why does it work as a .vbs file and not a .htm file?
|
| Thanks in advance.

The WScript object is only available when WSH-hosted (i.e., running directly
under wscript.exe or cscript.exe). By design, it is not available in any of
the HTML-hosted or XML-hosted formats, including HTAs (MSHTA-hosted) and
WSCs (although it can be handed into a WSC object from the the calling
script through an exposed property). The secondary WSH objects (e.g.,
WScript.Shell) and other primary objects (e.g., Err) are located in files
other than the WSH exe files and remain accessible by design. Only the
immediate WScript methods and properties are unavailable (most notably
including Sleep).

The WSH-hosted Script.CreateObject method and the standard WSH language
intrinsic CreateObject function are quite similar, except for the former's
ability to automatically sink events to procedures.

Use CreateObject instead of WScript.CreateObject.

Joe Earnest




---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.521 / Virus Database: 319 - Release Date: 09-23-03



Re: WScript.Shell works as .vbs file, doesn't work as .htm file by Tom

Tom
Mon Dec 01 18:55:50 CST 2003


"Ed White" <ewhite2142@hotmail.com> wrote in message
news:05d701c3b867$0a87cc80$a101280a@phx.gbl...
> When I double-click on the following file saved
> as "c:\test.vbs" it works:
>
> Dim wsh
> Set wsh = WScript.CreateObject("WScript.Shell")
> Wsh.Run("C:\testfile.exe")
>
> When I double-click on the following file saved
> as "c:\test.htm", I get RunTime Error "Line 4 Error:
> Object required: 'WScript'". Except for the HTML and
> SCRIPT lines, the files are identical (I copied and
> pasted the code from one to the other).
>
> <HTML>
> <SCRIPT LANGUAGE="vbscript" defer>
> Dim wsh
> Set wsh = WScript.CreateObject("WScript.Shell")
> Wsh.Run("C:\testfile.exe")
> </SCRIPT>
> </HTML>
>
> Why does it work as a .vbs file and not a .htm file?
>


Hi,
try this:
Set wsh = CreateObject("WScript.Shell")