Re: execute WSH in a js file from html?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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.
.



Relevant Pages

  • Re: A new HTA based message box
    ... unreasonable to give the script proper | access." ... same philosophy followed | when VBScript initiates an IE? ... effectively undo all the | security introduced by such distinction? ... an HTA is really the only way to do much of anything ...
    (microsoft.public.scripting.vbscript)
  • Re: get array from html
    ... I would have my standalone VBScript load the HTML file ... and then have the script do its thing of getting the info of interest. ... build other HTAs, called HTA Helpomatic. ...
    (microsoft.public.scripting.vbscript)
  • Re: get array from html
    ... I would have my standalone VBScript load the HTML file in an IE object and use the DOM to get at what I want. ... Of course, sometimes you can't get directly to the web page that you are interested in, so you may have to set up a way to pause your script while you manually navigate, in the script's IE window, to the page of interest, and then have the script do its thing of getting the info of interest. ... One fairly quick way to learn about how to manipulate many of the features of the HTML DOM is to study a Microsoft HTA that can be used to build other HTAs, ...
    (microsoft.public.scripting.vbscript)
  • Re: execute WSH in a js file from html?
    ... file to be made part of the script of the page. ... This would need very low security level on the browser but would allow files ... This is a security issue with client-side scripting. ... changing the extension from HTML to HTA. ...
    (microsoft.public.scripting.wsh)
  • Re: get array from html
    ... I don't know how to get the JScript array directly transferred to a VBScript ... I would have my standalone VBScript load the HTML file in an IE ... the script's IE window, to the page of interest, and then have the script do ... HTAs, called HTA Helpomatic. ...
    (microsoft.public.scripting.vbscript)