Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Simple VBscript Calling a function

Options
  • 29-02-2008 1:11am
    #1
    Registered Users Posts: 3,088 ✭✭✭


    Ive been at this for the last 5 hours and I cant seem to figure out whats going wrong, Ive tried about 15 other permutations using java code and other code I found on the web.

    I know its simple stuff but its baffling me at present, Im learning VB + HTML + JAVA as I go along but I still cant figure it out. I think the problem is in the Function calling somewhere

    For instance this works perfectly for me (as in it calls the program in question)
    I save it as a ".vbs" file
    Set wshShell = WScript.CreateObject ("WSCript.shell")
    wshshell.run """c:\JAWS450\jfw.exe""", 0, True
    set wshshell = nothing
    

    But this fella (save as a html) just wont work with me!
    <html>
    <head>
    
    <script language="vbscript">	Set shell = CreateObject("Wscript.Shell")	function "startJAWS()"    shell.Run """c:\JAWS450\jfw.exe""", 0, True    End function	function StopJAWS()    shell.Run "c:\JAWS450\stopjaws.bat", 0, True    End Function
    </script>
    
    </head>
    <body>
    
      <FORM NAME="frmExercise1">
    
        <INPUT TYPE="Button" NAME="startJAWS()" VALUE="Start Jaws NOW! please">
    
        <SCRIPT FOR="startJAWS()" EVENT="onClick" LANGUAGE="VBScript">
    
          MsgBox "A simple example of VBScript NOT in action."
    
        </SCRIPT>
    
      </FORM>
    
    <p>By pressing the button, a function will be called. The function will alert a message.</p>
    
    </body>
    </html>
    

    I'll keep at it tomorrow but if any kind stranger figures it out it would be MOST appreciated! :)


Comments

  • Moderators, Society & Culture Moderators Posts: 9,689 Mod ✭✭✭✭stevenmu


    I'm not totally sure what you're trying to do but your first part
    <script language="vbscript">	Set shell = CreateObject("Wscript.Shell")	function "startJAWS()"    shell.Run """c:\JAWS450\jfw.exe""", 0, True    End function	function StopJAWS()    shell.Run "c:\JAWS450\stopjaws.bat", 0, True    End Function
    </script>
    
    almost certainly won't work due to security issues. Embedding it like that with <script> tags will try to run the vbscript on the client side (i.e. it will be run in the users browser) which almost certainly won't be able to execute shell commands. Are you sure you don't want to run that on the server side? Maybe what you should be looking is ASP (which uses VBScript on the server)

    If you are trying to run client side stuff, I would also suggest you use javascript, vbscript is very poorly supported, I'm not sure if IE even still supports it, and I'm pretty sure nothing else does.


  • Registered Users Posts: 3,088 ✭✭✭Static M.e.


    Hi stevenmu,

    Thanks for your help! This is all very new to me.

    What I am actually trying to do is have two buttons in a html page where you can Click "Sound On" and "Sound Off"

    So for the Sound On button, when someone clicks the button a Function runs that basically runs the following application "c:\JAWS450\jfw.exe"

    For the Sound Off button, I had created a Bat file that runs a Killtask against the jfw.exe application so it essentially kills it, thereby knocking off the sound.

    The JAWS application (jfw.exe) is for blind people so it reads all the text on the screen, but the computer will be for everyones use so I dont want it on the whole time.

    The software and Webpage \ Webserver will be all located on single PC with a touchscreen, very similar to a kiosk setup.

    Ill have a look at Javascript, at least I know what language I should be writing in now :) Thanks


  • Closed Accounts Posts: 1,567 ✭✭✭Martyr


    this gives 2 warnings, but it worked for me.

    [PHP]Function startJAWS()

    CreateObject("WScript.Shell").Run "C:\windows\system32\notepad.exe",1,True

    End Function[/PHP]

    changed the form to this

    [HTML]
    <FORM NAME="frmExercise1">

    <INPUT TYPE="Button"
    NAME="appTest"
    VALUE="Start Jaws NOW! please"
    onClick="startJAWS()">

    </FORM>
    [/HTML]


  • Registered Users Posts: 3,088 ✭✭✭Static M.e.


    Hi Average Joe,

    Thanks for that input!!

    I got a major part working now, I think one of my problems was that I wasn't using double \\ in the "c:\\WINDOWS\\system32\\notepad.exe";
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head2" runat="server">
        <title>Run Executable HTA</title>
    
        <script language="javascript" type="text/javascript">
        function RunEXE()
        {
            var oShell = new ActiveXObject("WScript.Shell");
            var prog = "c:\\WINDOWS\\system32\\notepad.exe";
            oShell.Run('"'+prog+'"',1);
        }
        </script>
    
    </head>
    <body>
        <input id="Button1" onclick="RunEXE()" type="button" value="Notepad" />
    </body>
    </html>
    


  • Registered Users Posts: 3,088 ✭✭✭Static M.e.


    Just incase anyone else ever comes across this problem, my final code is
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head2" runat="server">
        <title>JAWS Start Stop</title>
    
        <script language="javascript" type="text/javascript">
        function StartJAWS()
        {
            var oShell = new ActiveXObject("WScript.Shell");
            var prog = "c:\\JAWS450\\jfw.exe";
            oShell.Run('"'+prog+'"',1);
        }
        function StopJAWS()
        {
            var oShell = new ActiveXObject("WScript.Shell");
            var prog = "c:\\Kill_JAWS.bat";
            oShell.Run('"'+prog+'"',1);
        }
        </script>
    
    </head>
    <body>
        <input id="Button1" onclick="StartJAWS()" type="button" value="Sound On" />
        <input id="Button1" onclick="StopJAWS()" type="button" value="Sound Off" />
    </body>
    </html>
    

    Thanks to everyone for your help and pointing me in the right direction!!


  • Advertisement
  • Users Awaiting Email Confirmation Posts: 351 ✭✭ron_darrell


    stevenmu wrote: »
    I'm not totally sure what you're trying to do but your first part
    <script language="vbscript">	Set shell = CreateObject("Wscript.Shell")	function "startJAWS()"    shell.Run """c:\JAWS450\jfw.exe""", 0, True    End function	function StopJAWS()    shell.Run "c:\JAWS450\stopjaws.bat", 0, True    End Function
    </script>
    
    almost certainly won't work due to security issues. Embedding it like that with <script> tags will try to run the vbscript on the client side (i.e. it will be run in the users browser) which almost certainly won't be able to execute shell commands. Are you sure you don't want to run that on the server side? Maybe what you should be looking is ASP (which uses VBScript on the server)

    If you are trying to run client side stuff, I would also suggest you use javascript, vbscript is very poorly supported, I'm not sure if IE even still supports it, and I'm pretty sure nothing else does.


    IE does and will continue to support VBScript (it being a MS created scripting language) but as you rightly pointed out it is not supported by any other browsers and as such is of limited use as a client side scripting tool. On the other hand it is the scripting language of choice for (Vanilla) ASP (though that can be written in javascript it is not really intended for it). VBScript will also give you a good feel for VBA (for writing Macros and automating forms in various MS Office products) and as a result for VB (old VB though a good feel for it's younger better looking cousin VB.Net as well) and for this reason it is a good idea to learn a little of it Steven (much as you would expose yourself to PERL or TCL even though these are not used that much these days (I'm sure hundreds of you will disagree with me on this point :D))


  • Registered Users Posts: 3,088 ✭✭✭Static M.e.


    <Bangs Head against Desk>

    Ive now been told the script needs to run on the SERVER side rather than the client side which I was told first.

    I take it I now need to change it to ASP to work on the server side or can it be simply converted to a server side script easily?

    The error it gives is "Error: Automation Server can't create object" Code:0


  • Users Awaiting Email Confirmation Posts: 351 ✭✭ron_darrell


    Hi OP - have to say this sounds like the wrong way to go about this. Much better to have the speech to text program run on login (as a service or statup program) and have an icon on the desktop to deactivate the program (until the next login) and maybe another to forcibly start it (if needed). If they insist on being able to activate/deactivate the program from a web page then I still don't see why it needs to reside on the server. What you are trying to do can only run from the client side (from my understanding of it anyways) and the error you are experiencing seems to back that up (the error basically means that an object of the type you are trying to create can't be found on the server).

    Sorry I can't be more help. But if you get any further I'd love to hear how.

    Regards,
    RD


  • Closed Accounts Posts: 1,567 ✭✭✭Martyr


    if JAWS is installed on the remote users PC, then could you control it using COM and Javascript?

    Is there jfwapi interface which allows you to control JAWS behaviour?

    i don't know if all this would solve your problem, but have a look at this forum posting:

    http://www.gammon.com.au/forum/?id=7767

    it appears that there is some COM functionality which allows you to toggle on/off the sound.
    all you'd be required to do is create the object and call the appropriate method.

    there may be some method such as, IsRunning() or whatever..so you don't bother toggling sound depending on if its already running.

    if you wanted to lookup the methods for some undocumented interface part of JAWS, check out ComView by Japheth.


  • Registered Users Posts: 3,088 ✭✭✭Static M.e.


    Hey Guys,
    Just to get back to you with an update, I got the script to run on the client PCs from the WebServer by Enabling all the ActiveX components under Tools\Options\Security\TrustedSites\Custom level.

    Because the PC\Kiosk will be locked down with no access to the desktop and\or no access to the internet except to 3/4 Sites, I think this is an acceptable risk.

    Once people can actually get the program Stopped and Started they will be more than happy, I realise that using a Start Application and Killtask to stop it, isn't that gracefull to say the least but for us it will solve the problem with the least amount of difficulty. The people who will be looking after the Kiosks will not be technical at all so the Start \ Stop buttons will work quite well for them.


    @ron_darrell. Thanks for the input, the reason they want the program to be run from the server side is to reduce the amount of work that has to go into each PC build, by keeping it all server side, its easier to manage becuase they can just change the server config and all the sites will change. They wont have to add/remove a site on each PC/Kiosk.

    @Average Joe. Again also thanks for the input. I quite like the way they are setting JAWS up, you can do alot of work using the Jaws config tools and advanced settings but for us, it could be a bit too much for the amount or use it will get. For me, its more of a Time Vs Function trade off, they just need it to be able to use Jaws on a On / Off situation should the need ever arise where a Blind individual needs to use the kiosk. I know my approach isnt clean but it should "Do the Job" so to speak.

    Thanks everyone again for your input, it was very helpful when I LOST :)


  • Advertisement
Advertisement