Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-10-2010, 06:33 PM   PM User | #1
zeek10452
New to the CF scene

 
Join Date: Sep 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
zeek10452 is an unknown quantity at this point
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
zeek10452 is offline   Reply With Quote
Old 09-10-2010, 08:00 PM   PM User | #2
Lerura
Regular Coder

 
Lerura's Avatar
 
Join Date: Aug 2005
Location: Denmark
Posts: 869
Thanks: 0
Thanked 112 Times in 111 Posts
Lerura will become famous soon enough
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.
Lerura is offline   Reply With Quote
Old 09-10-2010, 08:17 PM   PM User | #3
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,578
Thanks: 62
Thanked 4,063 Times in 4,032 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Old 09-10-2010, 08:18 PM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,578
Thanks: 62
Thanked 4,063 Times in 4,032 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Old 09-10-2010, 08:50 PM   PM User | #5
zeek10452
New to the CF scene

 
Join Date: Sep 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
zeek10452 is an unknown quantity at this point
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>
zeek10452 is offline   Reply With Quote
Old 09-10-2010, 09:01 PM   PM User | #6
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,578
Thanks: 62
Thanked 4,063 Times in 4,032 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Old 09-10-2010, 09:02 PM   PM User | #7
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,578
Thanks: 62
Thanked 4,063 Times in 4,032 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Old 09-11-2010, 08:18 AM   PM User | #8
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,103
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
Philip M is offline   Reply With Quote
Reply

Bookmarks

Tags
javascript, services

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:39 AM.


Advertisement
Log in to turn off these ads.