Re: execute WSH in a js file from html?
- From: Luting <houluting@xxxxxxxxx>
- Date: Mon, 30 Jun 2008 12:29:08 -0700 (PDT)
On Jun 30, 10:28 am, Tom Lavedas <tglba...@xxxxxxx> wrote:
On Jun 30, 12:30 pm, Luting <houlut...@xxxxxxxxx> wrote:
On Jun 30, 8:10 am, Tom Lavedas <tglba...@xxxxxxx> wrote:
On Jun 30, 10:31 am, Luting <houlut...@xxxxxxxxx> wrote:
On Jun 27, 12:24 am, "Joe Fawcett" <joefawc...@xxxxxxxxxxxxxxxx>
wrote:
"Al Dunbar" <AlanD...@xxxxxxxxxxxxxxxxxxx> wrote in message
news:#AH$Wx#1IHA.3968@xxxxxxxxxxxxxxxxxxxxxxx
"Luting" <houlut...@xxxxxxxxx> wrote in message
news:9a076733-b29d-49ca-b814-3b3c3c2535d2@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi all,
How can I execute a WSH program from html file? The wsh program is
stored in a .js file. I tried to include the .js file as usual:
<script type="text/javascript" src="XYZ.js">
</script>
But it didn't work.
The wsh itself works just fine when I double click on it.
Could you help me out?
The script tag you have shown will probably cause the content of the .js
file to be made part of the script of the page. But simply including it
does not cause it to run. For that you need to have some event fire the
script, or have some other script that is executed call a subroutine
defined within the .js file.
/Al
You can use the WScript.Shell's Run method to call CScript/WScript.
This would need very low security level on the browser but would allow files
that use the WScript.Sleep methods and the like to run.
If the files only contain stuff that could run in a browser environment
anyway you can include the file as you did and just call any functions
one-by-one.
--
Joe Fawcett (MVP - XML)http://joe.fawcett.name-Hidequotedtext-
- Show quoted text -
Hi,
I include the file and run the function I need. But it gave me an
error said "WScript is undefined."
I also tried this:
var oShell=WScript.CreateObject("WScript.shell");
oshell.Run(oApp,1,true);
oApp is the application I defined in the .js file.
This time I didn't get an error but the file was not executed at all.
How can I fix this?
Luting
In an html as the host, wscript is not available. That means its
CreateObject is also not available, but JS provides an alternative
function, ActiveXObject ...
var oShell=new ActiveXObject("WScript.Shell");
oshell.Run(oApp,1,true);
Note, that though the WScript object is not available other WSH
objects, like WScript.Shell, are resident in the wshom.ocx and
therefore they can be instantiated, regardless of the host.
Tom Lavedas
===========http://members.cox.net/tglbatch/wsh/-Hidequoted text -
- Show quoted text -
Thank you, Tom!
That helps a lot!
I changed my code into ActiveXObject() and it works fine, except that
there is always an alert window appearing when the page is loaded. Is
there any way to get rid of the alert window?
Luting
This is a security issue with client-side scripting. The
Wscript.Shell object is marked as 'unsafe for scripting' - which it
most certainly is. Therefore, the user must decide to alter their
security setting to eliminate this warning. Fotr a detailed
discussion of the subject see:http://groups.google.com/group/microsoft.public.scripting.vbscript/ms...
A common alternative is to convert your HTML application to a
Hypertext Application (HTA) instead. This substantially reduces or
eliminates such security requirements. Most HTMLs only require
changing the extension from HTML (HTM) to HTA. However, the file then
becomes an application that must be downloaded to and run from the
user's machine. It is no longer hosted by their browser.
Tom Lavedas
===========http://members.cox.net/tglbatch/wsh/- Hide quoted text -
- Show quoted text -
Hi Tom,
I really appreciate it.
The HTA solution really helps.
Thanks.
.
- References:
- execute WSH in a js file from html?
- From: Luting
- Re: execute WSH in a js file from html?
- From: Al Dunbar
- Re: execute WSH in a js file from html?
- From: Joe Fawcett
- Re: execute WSH in a js file from html?
- From: Luting
- Re: execute WSH in a js file from html?
- From: Tom Lavedas
- Re: execute WSH in a js file from html?
- From: Luting
- Re: execute WSH in a js file from html?
- From: Tom Lavedas
- execute WSH in a js file from html?
- Prev by Date: Re: execute WSH in a js file from html?
- Previous by thread: Re: execute WSH in a js file from html?
- Next by thread: VBS question
- Index(es):
Relevant Pages
|