WSH and ASP 
Author Message
 WSH and ASP

I was wondering if there was a way to get WSH to work on
an ASP page.  What I would really like to be able to do is
open a program (such as the calculator) and pass some
arguments to it (such as have it add some numbers
together).  If anybody knows how to do this please let me
know.

Thanks,
Jeremy



Wed, 06 Oct 2004 01:30:37 GMT  
 WSH and ASP
Sure...but you could write your own embedded calculator in script (or find one
on the Internet) and have it work much more reliably and without the security
restrictions.

Here is the code which the client would need to execute:

set oShell = CreateObject("WScript.Shell")
oShell.run("calc")

Note that this is not "ASP" code and really shouldn't be since running the
calculator on the server won't do you much good.  You also can't pass arguments
to it, which is one reason why just doing math you know needs to be done might
be better handled internally... and if you choose to implement a "virtual
calculator" which is just an HTML construct, you have the option of manipulating
it programmatically, unlike the Windows calculator.


Quote:
> I was wondering if there was a way to get WSH to work on
> an ASP page.  What I would really like to be able to do is
> open a program (such as the calculator) and pass some
> arguments to it (such as have it add some numbers
> together).  If anybody knows how to do this please let me
> know.

> Thanks,
> Jeremy



Wed, 06 Oct 2004 02:01:11 GMT  
 WSH and ASP
Thanks for the reply.  This is what I have (in VBScript):
<%
set WshShell = CreateObject("WScript.Shell")
WshShell.Run "C:\WinNT\System32\Calc.exe"
%>

What it does is start a process in the task manager, but
it doesn't bring up the application and when I try to end
it I get an Access denied error.  I tried your code and it
does the exact same thing.

What kind of security restrictions are you talking about?  
See, what I want to do is create an ASP page, have it run
on my local machine, and set my active desktop to that
page.  On that page I want to have links that will open up
the programs (when I try something like <a
href="c:\winnt\system32\calc.exe">Calculator</a> it tries
to download it vs. running it).

Quote:
>-----Original Message-----
>Sure...but you could write your own embedded calculator

in script (or find one
Quote:
>on the Internet) and have it work much more reliably and

without the security
Quote:
>restrictions.

>Here is the code which the client would need to execute:

>set oShell = CreateObject("WScript.Shell")
>oShell.run("calc")

>Note that this is not "ASP" code and really shouldn't be
since running the
>calculator on the server won't do you much good.  You

also can't pass arguments
Quote:
>to it, which is one reason why just doing math you know

needs to be done might
Quote:
>be better handled internally... and if you choose to

implement a "virtual
Quote:
>calculator" which is just an HTML construct, you have the

option of manipulating
Quote:
>it programmatically, unlike the Windows calculator.



>> I was wondering if there was a way to get WSH to work on
>> an ASP page.  What I would really like to be able to do
is
>> open a program (such as the calculator) and pass some
>> arguments to it (such as have it add some numbers
>> together).  If anybody knows how to do this please let
me
>> know.

>> Thanks,
>> Jeremy

>.



Wed, 06 Oct 2004 03:17:51 GMT  
 WSH and ASP
Calc (or any other program with a visible UI) is NOT a good candidate for execution from server side ASP. Whatever you execute can't display any UI that requires an interactive response of any kind under any circumstances, period, end of story, no exceptions, ...!!! There is *NO* interactive user and nothing runs in the context of the visible interactive desktop.

You can't kill it from Task Manager since it wasn't created in your security context as an intecative logged on user...

The kinds of programs that work best are console mode programs executed using

"%comspec% /c ... "

with redirected file input and output (if needed) and that do not under *any* circumstances go into an intereactive user prompt mode. And these programs (or even WSH CScript hosted scripts) *can* take command line arguments.

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--



Wed, 06 Oct 2004 03:36:43 GMT  
 WSH and ASP
I think I kind of understand what you're saying, but let
me see...  Since it's a web page that launches the
program, it's only the web page that has access to it
basically.  And since I launch it from a web page, me (as
a user) can't do anything with the program because it
belongs to the web page.  Am I right, or way out in left
field?

So why do you say the calculator is not a good candidate
for execution from server side ASP?

Also, if I understand why you're saying, I can execute a
DOS prompt from an ASP page using the comspec????  I'm
fairly new to scripting, and I've never heard of comspec
(but in my WSH help file it says it's the executable file
for the command prompt)...  How exactly does that work, do
you have a piece of code that I can look at?

Quote:
>-----Original Message-----
>Calc (or any other program with a visible UI) is NOT a

good candidate for execution from server side ASP.
Whatever you execute can't display any UI that requires an
interactive response of any kind under any circumstances,
period, end of story, no exceptions, ...!!! There is *NO*
interactive user and nothing runs in the context of the
visible interactive desktop.
Quote:

>You can't kill it from Task Manager since it wasn't

created in your security context as an intecative logged
on user...
Quote:

>The kinds of programs that work best are console mode

programs executed using
Quote:

>"%comspec% /c ... "

>with redirected file input and output (if needed) and

that do not under *any* circumstances go into an
intereactive user prompt mode. And these programs (or even
WSH CScript hosted scripts) *can* take command line
arguments.
Quote:

>--
>Michael Harris
>Microsoft.MVP.Scripting
>Seattle WA US
>--

>.



Wed, 06 Oct 2004 04:03:12 GMT  
 WSH and ASP
Actually, when you run it from ASP it's not the browser that has access to it.
It's ASP.

Say you are Jeremy on machine B and run an ASP page from machine A.  The code
running in ASP belongs to IUSR on machine A, and works in the context of IUSR on
machine A.

When you are sitting on machine A and running the code, it's still the same
thing.  IE calls ASP, and ASP runs it in its own context allowing the IUSR
account to access it - but IUSR is not logged on to an interactive GUI session
so it can never appear anywhere.  The only way to do that is to run it as
client-side HTML, not server-side ASP code.


Quote:
> I think I kind of understand what you're saying, but let
> me see...  Since it's a web page that launches the
> program, it's only the web page that has access to it
> basically.  And since I launch it from a web page, me (as
> a user) can't do anything with the program because it
> belongs to the web page.  Am I right, or way out in left
> field?

> So why do you say the calculator is not a good candidate
> for execution from server side ASP?

> Also, if I understand why you're saying, I can execute a
> DOS prompt from an ASP page using the comspec????  I'm
> fairly new to scripting, and I've never heard of comspec
> (but in my WSH help file it says it's the executable file
> for the command prompt)...  How exactly does that work, do
> you have a piece of code that I can look at?

> >-----Original Message-----
> >Calc (or any other program with a visible UI) is NOT a
> good candidate for execution from server side ASP.
> Whatever you execute can't display any UI that requires an
> interactive response of any kind under any circumstances,
> period, end of story, no exceptions, ...!!! There is *NO*
> interactive user and nothing runs in the context of the
> visible interactive desktop.

> >You can't kill it from Task Manager since it wasn't
> created in your security context as an intecative logged
> on user...

> >The kinds of programs that work best are console mode
> programs executed using

> >"%comspec% /c ... "

> >with redirected file input and output (if needed) and
> that do not under *any* circumstances go into an
> intereactive user prompt mode. And these programs (or even
> WSH CScript hosted scripts) *can* take command line
> arguments.

> >--
> >Michael Harris
> >Microsoft.MVP.Scripting
> >Seattle WA US
> >--

> >.



Wed, 06 Oct 2004 04:40:26 GMT  
 WSH and ASP
A "web page" (or more accurately an ASP page) has 2 script execution environments, usually on different machines but definitely in 2 different processes at are completely disconnected from each other.  

The first to execute is the server side ASP code (which is where you are using the Run method).  Server side is meant to build HTML to send back to the client browser, not start programs (on the server) to interact with the user (who could be on the other side of the planet)...

The second to execute is the client side script in the HTML that was sent back to the client browser.  Now *that* code *could* launch a program like calc or notepad on the *user's* machine.  But the browser has a strict security model that does not allow it unless the user approves it.

Any *good* book on web development should make all of this crystal clear.  If it doesn't, then it isn't a good book on the subject.

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--



Wed, 06 Oct 2004 04:56:35 GMT  
 WSH and ASP
Michael,

Thanks your reply.  I understand everything that you are
saying.  I'm not really concerend where it executes
(especially since this is for my own personal use, and in
my situation my server and client are the same machine).  
I'm not opening my computer up to the world to mess with
or anything like that.  

It doesn't have to be ASP that executes the code, if I can
do it on the client side that should work for me.  Bottom
line, my question is how do I do it?  Again, I don't care
if it's server side or client side since it will run off
my own personal computer.

Thanks for your help,
Jeremy

Quote:
>-----Original Message-----
>A "web page" (or more accurately an ASP page) has 2

script execution environments, usually on different
machines but definitely in 2 different processes at are
completely disconnected from each other.  
Quote:

>The first to execute is the server side ASP code (which

is where you are using the Run method).  Server side is
meant to build HTML to send back to the client browser,
not start programs (on the server) to interact with the
user (who could be on the other side of the planet)...
Quote:

>The second to execute is the client side script in the

HTML that was sent back to the client browser.  Now *that*
code *could* launch a program like calc or notepad on the
*user's* machine.  But the browser has a strict security
model that does not allow it unless the user approves it.
Quote:

>Any *good* book on web development should make all of

this crystal clear.  If it doesn't, then it isn't a good
book on the subject.
Quote:

>--
>Michael Harris
>Microsoft.MVP.Scripting
>Seattle WA US
>--

>.



Wed, 06 Oct 2004 05:21:19 GMT  
 WSH and ASP

Quote:
> It doesn't have to be ASP that executes the code, if I can
> do it on the client side that should work for me.  Bottom
> line, my question is how do I do it?  Again, I don't care
> if it's server side or client side since it will run off
> my own personal computer.

I would just write an HTA (HTML Application) that runs locally (no ASP involved).

Save the example below as MyHTA.hta and double-click it in Windows Explorer to run it (I assume you have at least IE5 installed).

<html><head><title>MyHTA</title>
<hta:application
  applicationname="myHTA"  
  singleinstance="yes"    
/>
<style>
.btn {width:150px;}
</style>
<script language="vbscript">
sub launch(pgm)
  set shell = createobject("wscript.shell")
  shell.run pgm
end sub
</script>
</head>
<body>
<input onclick='launch "calc.exe"'
  type="button" class="btn" value="run calc"><br>
<input onclick='launch "notepad.exe"'
  type="button" class="btn"value="run notepad">
</body>
</html>

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--



Wed, 06 Oct 2004 05:47:18 GMT  
 WSH and ASP
Michael,

That script seems to work okay.  My only problem with it
is when I go to the .hta page I get a prompt to open or
save the file (which I don't like), it's also a lot
different than "normal" web pages by that I mean it
doesn't seem to act the same in the browser.  My virus
protection also tries to stop it from running.

Is there really no way of launching applications from an
ASP page?  I already understand ASP technology, and I know
nothing about HTA but from what I understand there are a
lot of security issues with HTA, HTW, and HTX files.  

So there is really no way to execute an application with
ASP, not even something like server.execute???

Thanks again for your help!

Quote:
>-----Original Message-----
>> It doesn't have to be ASP that executes the code, if I
can
>> do it on the client side that should work for me.  
Bottom
>> line, my question is how do I do it?  Again, I don't
care
>> if it's server side or client side since it will run off
>> my own personal computer.

>I would just write an HTA (HTML Application) that runs

locally (no ASP involved).
Quote:

>Save the example below as MyHTA.hta and double-click it

in Windows Explorer to run it (I assume you have at least
IE5 installed).
Quote:

><html><head><title>MyHTA</title>
><hta:application
>  applicationname="myHTA"  
>  singleinstance="yes"    
>/>
><style>
>..btn {width:150px;}
></style>
><script language="vbscript">
>sub launch(pgm)
>  set shell = createobject("wscript.shell")
>  shell.run pgm
>end sub
></script>
></head>
><body>
><input onclick='launch "calc.exe"'
>  type="button" class="btn" value="run calc"><br>
><input onclick='launch "notepad.exe"'
>  type="button" class="btn"value="run notepad">
></body>
></html>

>--
>Michael Harris
>Microsoft.MVP.Scripting
>Seattle WA US
>--

>.



Wed, 06 Oct 2004 11:32:39 GMT  
 WSH and ASP
If this is intended strictly for your local personal use, why are you accessing it (the HTA) via the browser form IIS?  

To launch apps from directly client side browser code requires that you lower security in the relevant security zone. Even when delivered from a local amchine instance of IIS, this still means adjusting Intranet zone security.

Just run the HTA directly without involving IIS or the browser...

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--



Wed, 06 Oct 2004 12:01:51 GMT  
 WSH and ASP
Jeremy, to use an HTML page as "Active Wallpaper", just use client side scripting.  A very basic example:

<html>
<head>
<script language=vbscript>
Sub RunProg(prog)
  Set ws = CreateObject("WScript.Shell")
  ws.Run chr(34) & prog & chr(34)
  Set ws = Nothing
End Sub
</script>
<style>a{cursor:hand}</style>
</head>
<body bgcolor="blue"><div align=center>
<a onClick=RunProg("explorer.exe")>Windows Explorer</a><br>
<a onClick=RunProg("msimn.exe")>Outlook Explress</a><br>
<a onClick=RunProg("iexplore.exe")>Internet Explorer</a><br>
<a onClick=RunProg("winword.exe")>Word</a><br>
<a onClick=RunProg("notepad.exe")>Notepad</a>
</div></body>
</html>

--

Bill James
Microsoft MVPDTS

Win9x VBScript Utilities ? www.billsway.com/vbspage/
Windows Tweaks & Tips ? www.billsway.com/notes_public/

Quote:

> I was wondering if there was a way to get WSH to work on
> an ASP page.  What I would really like to be able to do is
> open a program (such as the calculator) and pass some
> arguments to it (such as have it add some numbers
> together).  If anybody knows how to do this please let me
> know.

> Thanks,
> Jeremy



Wed, 06 Oct 2004 12:22:38 GMT  
 
 [ 12 post ] 

 Relevant Pages 

1. WSH no ASP Question

2. Running WSH from ASP

3. Help with using ADO in WSH not ASP.

4. WSH and ASP

5. How can I use WSH in ASP?

6. The error on WSH within ASP programming!

7. WSH in ASP : mysticism

8. WSH with ASP

9. More wsh with asp...help!!!!...again

10. Using WSH in Asp

11. More wsh with asp...help!!!!

12. WSH and ASP

 

 
Powered by phpBB® Forum Software