Works as VBS but not in HTM page 
Author Message
 Works as VBS but not in HTM page

I have this code that will telnet to my server and connect it to the
internet.
It works fine as a VBS, but when I put it behind a button on a Web Page
(.htm) It doesn't.
I beleive I have to make som e sutble conversions, but what and where?

Here is the code from the .htm

<html>
<head>
  <title>Server Internet Connection</title>
</head>

<script language="VBScript">

  Sub btnAction_onClick(MyDirection)
 if MyDirection = 1 then

  set wshbin = createobject("wscript.shell")
  output = wshbin.run("telnet 192.168.2.100")
  wscript.sleep(500)
  wshbin.Sendkeys "username~"
  wscript.sleep(1000)
  wshbin.Sendkeys "password~"
  wscript.sleep(1000)
  wshbin.Sendkeys "dun up" 'My Server Dial Up Command
  Wscript.sleep(2000)
  wshbin.Sendkeys "~"
  wshbin.Sendkeys "exit~"

 elseif MyDirection = 2 then
  'for testing I have used Sol.exe
  CreateObject("Wscript.Shell").Run "sol.exe"
 end if
  End Sub

</script>

 <body>
   To Connect to the net now
   <input type="button" name="btnDunUp" value="Get Connected"
onClick="btnAction_onClick(1)">
   <p>
   And When you have finished
 '  <input type="button" name="btnDunDown" value="Get Off Mow"
onClick="btnAction_onClick(2)">
   <p>

  </body>
</html>



Fri, 06 Feb 2004 17:26:34 GMT  
 Works as VBS but not in HTM page

Quote:
>   set wshbin = createobject("wscript.shell")

You can't do that via a web page for security reasons.  Would you want a web
page shelling EXEs on your machine?


Fri, 06 Feb 2004 18:02:14 GMT  
 Works as VBS but not in HTM page
Yes I do!  Why else would I be coding it!

I have 5 PC's in my house, One has a modem in and NAT software so we can all
connect and browse.  I am creating a web page that shows the status of the
connection in the bottom frame and gives a connect & disconnect button in
the bottom frame.

I have been trying the new exec methood (5.6) to run telnet to the server to
get it to connect & disconnect, but FTP won't give stdout or stderr to allow
me to do that, so I have to shell out and run telnet with sendkeys (hardly
glamorous but it'll do).

So can anybody actually tell me what I need to do to make this VBS to work
in my HTM (or hta if I need to)?


Quote:
> >   set wshbin = createobject("wscript.shell")

> You can't do that via a web page for security reasons.  Would you want a
web
> page shelling EXEs on your machine?



Fri, 06 Feb 2004 20:45:58 GMT  
 Works as VBS but not in HTM page
Change the security settings on your browser to allow the creation of unsafe
controls.


Quote:
> Yes I do!  Why else would I be coding it!

> I have 5 PC's in my house, One has a modem in and NAT software so we can
all
> connect and browse.  I am creating a web page that shows the status of the
> connection in the bottom frame and gives a connect & disconnect button in
> the bottom frame.

> I have been trying the new exec methood (5.6) to run telnet to the server
to
> get it to connect & disconnect, but FTP won't give stdout or stderr to
allow
> me to do that, so I have to shell out and run telnet with sendkeys (hardly
> glamorous but it'll do).

> So can anybody actually tell me what I need to do to make this VBS to work
> in my HTM (or hta if I need to)?



> > >   set wshbin = createobject("wscript.shell")

> > You can't do that via a web page for security reasons.  Would you want a
> web
> > page shelling EXEs on your machine?



Fri, 06 Feb 2004 21:47:33 GMT  
 Works as VBS but not in HTM page
I'm actually getting the error
object required wscript
What does that mean to me?


Quote:
> Change the security settings on your browser to allow the creation of
unsafe
> controls.



> > Yes I do!  Why else would I be coding it!

> > I have 5 PC's in my house, One has a modem in and NAT software so we can
> all
> > connect and browse.  I am creating a web page that shows the status of
the
> > connection in the bottom frame and gives a connect & disconnect button
in
> > the bottom frame.

> > I have been trying the new exec methood (5.6) to run telnet to the
server
> to
> > get it to connect & disconnect, but FTP won't give stdout or stderr to
> allow
> > me to do that, so I have to shell out and run telnet with sendkeys
(hardly
> > glamorous but it'll do).

> > So can anybody actually tell me what I need to do to make this VBS to
work
> > in my HTM (or hta if I need to)?



> > > >   set wshbin = createobject("wscript.shell")

> > > You can't do that via a web page for security reasons.  Would you want
a
> > web
> > > page shelling EXEs on your machine?



Sat, 07 Feb 2004 16:42:53 GMT  
 Works as VBS but not in HTM page

Quote:
> I'm actually getting the error
> object required wscript
> What does that mean to me?

On what line?  It could be that you don't have WSH installed.  Look in the
registry under KHEY_CLASSES_ROOT to try and find the key "wscript.shell".

Also don't do this;

CreateObject("Wscript.Shell").Run "sol.exe"

do;

set obj = CreateObject("Wscript.Shell")
obj.Run "sol.exe"
set obj = nothing



Sat, 07 Feb 2004 16:57:06 GMT  
 Works as VBS but not in HTM page

Line 10 when I try to sleep is the first line that errors
When I use my second button (running sol.exe) that works fine.
It's only this first section troubling me
But when I use line 8 - 18 in a standalone VBS it works great.

how do I create a wscript object on this page??

<html>
<head>
  <title>Server Internet Connection</title>
</head>
<script language="VBScript">
  Sub btnAction_onClick(MyDirection)
 if MyDirection = 1 then
  set wshbin = createobject("wscript.shell")
  output = wshbin.run("telnet 192.168.2.100")
  wscript.sleep(500)
  wshbin.Sendkeys "bebox~"
  wscript.sleep(1000)
  wshbin.Sendkeys "bebox~"
  wscript.sleep(1000)
  wshbin.Sendkeys "help"
  Wscript.sleep(2000)
  wshbin.Sendkeys "~"
  wshbin.Sendkeys "exit~"
 elseif MyDirection = 2 then
  'for testing I have used Sol.exe
  CreateObject("Wscript.Shell").Run "sol.exe"
 end if
  End Sub
</script>

 <body>
   To Connect to the net now
   <input type="button" name="btnDunUp" value="Get Connected" onClick="btnAction_onClick(1)">  
   <p>
   And When you have finished
   <input type="button" name="btnDunDown" value="Get Off Now" onClick="btnAction_onClick(2)">  
   <p>

  </body>
</html>

Quote:

> > I'm actually getting the error
> > object required wscript
> > What does that mean to me?

> On what line?  It could be that you don't have WSH installed.  Look in the
> registry under KHEY_CLASSES_ROOT to try and find the key "wscript.shell".

> Also don't do this;

> CreateObject("Wscript.Shell").Run "sol.exe"

> do;

> set obj = CreateObject("Wscript.Shell")
> obj.Run "sol.exe"
> set obj = nothing



Sat, 07 Feb 2004 17:31:19 GMT  
 Works as VBS but not in HTM page

Ok, now I see.  On an HTML page there is no wscript object, that is provided for you by the WSH which is why it works in a VBS file.  I don't really know the equiv of such a sleep function in VBS on a web page.  You could try looping until the current time is 5 seconds in advance which you can work out using the DateAdd function

  Line 10 when I try to sleep is the first line that errors
  When I use my second button (running sol.exe) that works fine.
  It's only this first section troubling me
  But when I use line 8 - 18 in a standalone VBS it works great.

  how do I create a wscript object on this page??

  <html>
  <head>
    <title>Server Internet Connection</title>
  </head>
  <script language="VBScript">
    Sub btnAction_onClick(MyDirection)
   if MyDirection = 1 then
    set wshbin = createobject("wscript.shell")
    output = wshbin.run("telnet 192.168.2.100")
    wscript.sleep(500)
    wshbin.Sendkeys "bebox~"
    wscript.sleep(1000)
    wshbin.Sendkeys "bebox~"
    wscript.sleep(1000)
    wshbin.Sendkeys "help"
    Wscript.sleep(2000)
    wshbin.Sendkeys "~"
    wshbin.Sendkeys "exit~"
   elseif MyDirection = 2 then
    'for testing I have used Sol.exe
    CreateObject("Wscript.Shell").Run "sol.exe"
   end if
    End Sub
  </script>

   <body>
     To Connect to the net now
     <input type="button" name="btnDunUp" value="Get Connected" onClick="btnAction_onClick(1)">  
     <p>
     And When you have finished
     <input type="button" name="btnDunDown" value="Get Off Now" onClick="btnAction_onClick(2)">  
     <p>

    </body>
  </html>


  > > I'm actually getting the error
  > > object required wscript
  > > What does that mean to me?
  >
  > On what line?  It could be that you don't have WSH installed.  Look in the
  > registry under KHEY_CLASSES_ROOT to try and find the key "wscript.shell".
  >
  > Also don't do this;
  >
  > CreateObject("Wscript.Shell").Run "sol.exe"
  >
  > do;
  >
  > set obj = CreateObject("Wscript.Shell")
  > obj.Run "sol.exe"
  > set obj = nothing
  >
  >
  >



Sat, 07 Feb 2004 19:57:57 GMT  
 Works as VBS but not in HTM page
"...  I don't really know the equiv of such a sleep function in VBS on a web page. ..." You could

ScriptX (www.meadroid.com) has a comparable Wait method which is in the feature subset that is free
(no licen$e required)...

--
Michael Harris
Microsoft.MVP.Scripting
--

Please do not email questions - post them to the newsgroup instead.
--



Sun, 08 Feb 2004 03:21:12 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. VBS in a HTM or HTML page ?

2. embed a new htm page into an main page

3. onload vbs not working on website

4. vbs code to toggle Registry setting not working

5. Sending MAPI message works from .vbs, but not in ASP

6. VBA Script works but VBS Does not

7. Help...Why my vbs not working Properly.

8. VBS scripts not working

9. ByRef not working in WSH/VBS

10. win2k resource kit VBS files do not work with WMI or WBEM

11. Still not working (*vbs files) NEW to VBScript

12. Not Working(file saved as *.vbs)

 

 
Powered by phpBB® Forum Software