Using jscript for logon script

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrew

    Using jscript for logon script

    I have written a jscript that is executed when the user logs into the
    network. Among other things, I want the script to be able to run an
    executable which is stored on the network. Can anyone tell me the proper
    syntax for this? I think the line, WshShell.Run, is to be used but unsure
    of how it would be written.

    Thank You


  • Andrew Urquhart

    #2
    Re: Using jscript for logon script

    On Tue, 05 Aug 2003 22:14:51 GMT, Andrew <beveridgea@rog ers.com> wrote:
    [color=blue]
    > I have written a jscript that is executed when the user logs into the
    > network. Among other things, I want the script to be able to run an
    > executable which is stored on the network. Can anyone tell me the proper
    > syntax for this? I think the line, WshShell.Run, is to be used but
    > unsure
    > of how it would be written.[/color]

    Here's an example of how to use a shell object, in this case to execute a
    "net send" and check if the execution was successful:

    var oShell = new ActiveXObject(" WScript.Shell") ;
    ....
    var cmd = "%ComSpec% /c net send " + machine + " \"" + msg + "\"";
    var windowReturnCod e = oShell.Run(cmd, 0, true);

    var statusmessage = "Failed to send message\r\n";
    switch (windowReturnCo de) {
    case 0 : statusmessage = "Message successfully sent"; break;
    case 2 : statusmessage += "The computer could not be found on the
    network."; break;
    default : statusmessage += "Error code: " + windowReturnCod e;
    }
    ....

    Adapt it for your own needs and add a liberal sprinkling of try and
    catches. The switch is acting on the return code that the shell received
    upon execution of the command.

    More details in the Windows Script Host docs that are buried somewhere on
    Microsft's MSDN site.
    --
    Andrew Urquhart
    - http://www.andrewu.co.uk/clj.asp
    - FAQ for comp.lang.javas cript by Jim Ley at http://jibbering.com/faq
    - Archive at http://groups.google.com/groups?grou...ang.javascript

    Comment

    • Andrew

      #3
      Re: Using jscript for logon script

      I used x.Run(\\\\serve r\\share\\filen ame);

      This works fine, however, I also need to pass some parameters encased in
      double quotes. The above statement doesn't allow more than the two already
      used. This is the statement I am trying to call accross the network:

      \\server\share\ filename "\\server\share \filename -
      s -f1\\server\shar e\filename -f2\c:filename"

      When I use the above in a .bat file it works great. The problem is finding
      the right syntax to do the same thing in a .js file

      Any help would be appreciated...s orry about double posting. I didn't
      realize there was this group at first.




      "Evertjan." <exjxw.hannivoo rt@interxnl.net > wrote in message
      news:Xns93CF598 192A56eejj99@19 4.109.133.29...[color=blue]
      > Andrew wrote on 06 aug 2003 in comp.lang.javas cript and seperately in
      > microsoft.publi c.scripting.jsc ript:[color=green]
      > > I have written a jscript that is executed when the user logs into the
      > > network. Among other things, I want the script to be able to run an
      > > executable which is stored on the network. Can anyone tell me the
      > > proper syntax for this? I think the line, WshShell.Run, is to be used
      > > but unsure of how it would be written.[/color]
      >
      > Please never multipost !
      >
      > Crossposting is ok.
      >
      > Now you have two people giving the same help.
      >
      >
      > --
      > Evertjan.
      > The Netherlands.
      > (Please change the x'es to dots in my emailaddress)[/color]


      Comment

      • Michael Harris \(MVP\)

        #4
        Re: Using jscript for logon script

        > I used x.Run(\\\\serve r\\share\\filen ame);[color=blue]
        >
        > This works fine, however, I also need to pass some parameters encased
        > in double quotes. The above statement doesn't allow more than the
        > two already used. This is the statement I am trying to call accross
        > the network:
        >
        > \\server\share\ filename "\\server\share \filename -
        > s -f1\\server\shar e\filename -f2\c:filename"
        >
        > When I use the above in a .bat file it works great. The problem is
        > finding the right syntax to do the same thing in a .js file
        >[/color]

        You can just use single quotes to enclose a string literal that includes
        double quotes as in:

        'this thing "that thing"'

        So that would mean (all on one line)...

        x.Run('\\\\serv er\\share\\file name
        "\\\\server\\sh are\\filename -s -f1\\\\server\\s hare\\filename -f2
        c:filename"');

        --
        Michael Harris
        Microsoft.MVP.S cripting
        Seattle WA US

        Technet Script Center
        Gain technical skills through documentation and training, earn certifications and connect with the community


        Microsoft® Windows®2000 Scripting Guide
        Gain technical skills through documentation and training, earn certifications and connect with the community


        Comment

        Working...