Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Sep 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Restart A specific Service with Javascript

    I was wondering if its possible to have javascript stop a service on my machine for instance terminal services and then start it again...Any help provided will be greatly appreciated

  • #2
    Regular Coder Lerura's Avatar
    Join Date
    Aug 2005
    Location
    Denmark
    Posts
    945
    Thanks
    0
    Thanked 129 Times in 128 Posts
    Javascript cannot do anything to the system, like starting/killing/affecting processes
    or creating/editing/deleting files.
    It can only read the files, if and only if: the script is run from a local file.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,449
    Thanks
    76
    Thanked 4,373 Times in 4,338 Posts
    Well, actually it *COULD* do it on Windows, using MSIE. If you created (or found) an ActiveX control and installed it to your browser and allowed it to do "unsafe scripting" and didn't mind having to answer "yes, I know this is a bad thing to do" every time you ran the page. <grin/>
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,449
    Thanks
    76
    Thanked 4,373 Times in 4,338 Posts
    Oh, and yes JS in MSIE can write local files. Again, you have to permit it to every time you run the page. But it can.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    New to the CF scene
    Join Date
    Sep 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The javascript will be ran from within an already built application...I just need the JS code for stopping a service...would either of these codes be enough to get the job done:

    Code:
    <script>
    oShell = new ActiveXObject("WSCript.shell");
    oShell.run("NET START [service]");
    ////Or ////
    oShell.run("NET STOP [service]");
    </script>
    Code:
    <script language="JScript" runat="server">
    try{
      var fullPath = "C:\Program Files\Common Files\Apple\Mobile Device Support\AppleMobileDeviceService.exe",
      oServer = GetObject(fullPath);
      oServer.Stop();
      oServer.Start();
    }
    </script>

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,449
    Thanks
    76
    Thanked 4,373 Times in 4,338 Posts
    The second of those would work in ASP (if it works at all, that is), *NOT* in the browser. That's what runat="server" means.

    The first of those *could* also be run using ASP, if you used the same runat="server". I dunno if it will work from the browser. Never tried using Wscript.Shell from the browser. But clearly the "new ActiveXObject( )" syntax is the way to use ActiveX in the browser.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,449
    Thanks
    76
    Thanked 4,373 Times in 4,338 Posts
    One problem you have is that if you do use ASP, the code will run as the IUSR_xxxx user (where "xxxx" is the name of the computer). That's the user that IIS runs as. So you'd have to give that user permission to do the NET commands.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #8
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,990
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    Quote Originally Posted by Old Pedant View Post
    Oh, and yes JS in MSIE can write local files. Again, you have to permit it to every time you run the page. But it can.
    Internet Explorer lets you write to the Windows file system by means of the harmless execCommand() function. But reading from a file requires ActiveX which is not recommended for several reasons.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •