locked
JScript problems RRS feed

  • Question

  • I don't know if I'm in the right place to post this so forgive me if I am not. I have a home automation computer and part of it's functions is to run macro's. I have been able to get it to turn on media player 9 and play a playlist. But I am having trouble getting it to shut if off. After trying every command line string I could find I'm now looking into JScript. The particular part of JScript I'm looking at is the sendkey functon. Now I'm as new to this as fresh paint on a wall. I have created a script but it doesn't work, go figure. So I tried one of the scripts in the turtoial it doesn't work either, same error. here is the script I created maybe one of you can tell me where I have gone astray.
    <job id="js">
          <script language="JScript">
    var WshShell = WScript.createObject ("WScript.Shell");
    WshShell.exit("wmplayer")
    WScript.Sleep(100);
    WshShell.SendKeys("%fx")
    /script>
    /job/

    The error code does not like the < or > charactors in the beginning or the end of the script it wants a ! at the 5 space first line  once you do that it wants the < > gone at the end and / put there then it takes you back to the beginning and wants more. Any ideas why it won't work. If you want I will post the one from tutorial that also doesn't work.
    Sunday, April 17, 2005 9:15 PM

Answers

  • Ok I have it after several attemps I finally figured it out. I was using the wrong command run. exit is not a valid operation so you have to start the program by using run which is. The script now starts media player then shuts it of. For my purpose I just need to shut it off. So I start media player another way and this script will make the media window active then shut it off. Thanks so much for the help.

    var WshShell = WScript.createObject("WScript.Shell");
    WshShell.run("wmplayer");
    WScript.Sleep(100);
    WshShell.Appactivate("Wmplayer");
    WScript.sleep(2500);
    WshShell.SendKeys("%fx");
    Tuesday, April 19, 2005 3:08 PM

All replies

  • Some things to check:

    1. If you want to use the job syntax as in this example, you need to save it as a .wsf file. For a .js file, you need to nuke the tags and just include the contents for the script tag.

    2. The end tags for script and job in your post are missing the greater than. Not sure if this is what you have in the script. It may just be a side effect of this forum software.

    If you haven't already, you should check out the Script Center page at  http://www.microsoft.com/technet/scriptcenter/default.mspx which contains articles, FAQ's, etc.

    Monday, April 18, 2005 5:59 AM
    Moderator
  • Buy NUKE I'm guessing you mean to loose the tags all togeather if I save as .js keep them if I save as .wsf correct?? The end tags I need to replace the <> charactors is this correct ??? It's a pain dealing with dummies like myself so I apologize in advance. I will give this a try and report back. Thank you for your assistance.
    Monday, April 18, 2005 4:44 PM
  • Yes. The contents should contain the following if saved as .wsf file:
    <job id="js">
       <script language="JScript">
    var WshShell = WScript.createObject ("WScript.Shell");
    WshShell.exit("wmplayer")
    WScript.Sleep(100);
    WshShell.SendKeys("%fx")
       </script>
    </job>

    It should contain the following if saved as a .js file:
    var WshShell = WScript.createObject ("WScript.Shell");
    WshShell.exit("wmplayer")
    WScript.Sleep(100);
    WshShell.SendKeys("%fx")

    Monday, April 18, 2005 4:54 PM
    Moderator
  • Ok this is what I get when I run the .js

    line: 2
    Char:1
    error: Object doesn't support this propertiy or method
    Code: 800A01B6
    source: Microsoft JScript runtime error

    Here is what I get with the .wsh file it is a shortcut icon that it is saved as if that means anything.

    There is no script file specified.

    Maybe in the js case I should separate the keys instead of grouping them. This is all greek how they do this and I really can't figure out how it works. Even the file in the turtorial they wrote didn't work. I have downloaded debuggers can't get that to work either. downloaded windows script v5.6 don't know if that works or not. About ready to light the fuse and leave the building.

    Monday, April 18, 2005 6:00 PM
  • Ok I have it after several attemps I finally figured it out. I was using the wrong command run. exit is not a valid operation so you have to start the program by using run which is. The script now starts media player then shuts it of. For my purpose I just need to shut it off. So I start media player another way and this script will make the media window active then shut it off. Thanks so much for the help.

    var WshShell = WScript.createObject("WScript.Shell");
    WshShell.run("wmplayer");
    WScript.Sleep(100);
    WshShell.Appactivate("Wmplayer");
    WScript.sleep(2500);
    WshShell.SendKeys("%fx");
    Tuesday, April 19, 2005 3:08 PM