Welcome Guest.   Make a donation to an author on the site October 22, 2014, 08:38:40 PM  *

Please login or register.
Or did you miss your validation email?


Login with username and password (forgot your password?)
Why not become a lifetime supporting member of the site with a one-time donation of any amount? Your donation entitles you to a ton of additional benefits, including access to exclusive discounts and downloads, the ability to enter monthly free software drawings, and a single non-expiring license key for all of our programs.


You must sign up here before you can post and access some areas of the site. Registration is totally free and confidential.
 
The N.A.N.Y. Challenge 2013! Download dozens of custom programs!
   
   Forum Home   Thread Marks Chat! Downloads Search Login Register  
Pages: [1]   Go Down
  Reply  |  New Topic  |  Print  
Author Topic: Activate/deactive a windows service with a script  (Read 2398 times)
Contro
Participant
*
Posts: 2,171

View Profile Give some DonationCredits to this forum member
« on: August 04, 2012, 08:09:11 AM »

Activate/deactive a windows service with a script

I would like to be able with a script to activate a windows service for windows xp pro
The same, but deactivate that service.

P.D. Really I would like to run or stop the service, but may be more general and allow in some cases to abilitate the service o eliminate.

Best Regards
Logged
Stoic Joker
Honorary Member
**
Posts: 5,326



View Profile WWW Give some DonationCredits to this forum member
« Reply #1 on: August 04, 2012, 08:19:16 AM »

net stop [service name]
net start [service name]
net restart [service name]
Logged
AbteriX
Charter Honorary Member
***
Posts: 1,050


Member #520

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #2 on: August 04, 2012, 09:03:18 AM »

Quote
C:\>sc

DESCRIPTION:
        SC is a command line program used for communicating with the
        NT Service Controller and services.
USAGE:
        sc <server> [command] [service name] <option1> <option2>...
Logged

Greetings, Stefan.
Contro
Participant
*
Posts: 2,171

View Profile Give some DonationCredits to this forum member
« Reply #3 on: August 04, 2012, 10:19:32 AM »

 embarassed

Trying. i will comment. Are bat files ?¿
 Kiss
Logged
Shades
Member
**
Posts: 1,670


see users location on a map View Profile Give some DonationCredits to this forum member
« Reply #4 on: August 04, 2012, 05:40:08 PM »

Watch out with 'sc'.

At least read the manual very carefully, as it is quite a powerful tool. And it can wreak havoc in your system if you select (unintentionally) the wrong option for any (critical) service running in Windows.

Just sayin'.
Logged
Stoic Joker
Honorary Member
**
Posts: 5,326



View Profile WWW Give some DonationCredits to this forum member
« Reply #5 on: August 05, 2012, 09:22:28 AM »

^Very good point^  Thmbsup
Logged
AndyM
Charter Member
***
Posts: 616


see users location on a map View Profile Give some DonationCredits to this forum member
« Reply #6 on: August 05, 2012, 01:53:39 PM »

I have two batch files to turn on and off 2 services:
[copy or print]
ServicesStart.bat:

@echo off
sc config wuauserv start= auto
sc config BITS start= auto
sc start wuauserv
sc start BITS


ServicesStop.bat

@echo off
sc config wuauserv start= disabled
sc config BITS start= disabled
sc stop wuauserv
sc stop BITS
Both have worked fine (Windows XP SP3) for years.
Logged
mwb1100
Supporting Member
**
Posts: 1,330


View Profile Give some DonationCredits to this forum member
« Reply #7 on: August 05, 2012, 11:24:36 PM »

One nit to be aware of with sc is that the options that use an "=" sign are very particular about the whitespacing.  The "=" sign is actually part of the option name, so there cannot be a space before the equal sign, and there *must* be a space after.  So

[copy or print]
sc config wuauserv start= disabled

But not:

[copy or print]
sc config wuauserv start = disabled
sc config wuauserv start=disabled
Logged
IainB
Supporting Member
**
Posts: 4,790


Slartibartfarst

see users location on a map View Profile Give some DonationCredits to this forum member
« Reply #8 on: August 06, 2012, 12:07:00 AM »

net stop [service name]
net start [service name]
net restart [service name]
Thanks @Stoic Joker. I had not known of this command previously.
That's interesting. In Win7-64, the "NET" command only has these options - i.e., no RESTART:


« Last Edit: August 06, 2012, 12:15:43 AM by IainB; Reason: Minor correction. » Logged
IainB
Supporting Member
**
Posts: 4,790


Slartibartfarst

see users location on a map View Profile Give some DonationCredits to this forum member
« Reply #9 on: August 06, 2012, 12:32:13 AM »

I have two batch files to turn on and off 2 services:
[copy or print]
ServicesStart.bat:
@echo off
sc config wuauserv start= auto
...
Both have worked fine (Windows XP SP3) for years.
Thanks @AndyM. I had not known of this command previously.
In Win7-64, the "SC" has these options (see image below).
I see that config is "persistent" and QUERY and QUERYEX look like they could be useful for avoiding redundant toggles - e.g., START or STOP of an already started or stopped service.

Logged
skwire
Global Moderator
*****
Posts: 4,113



Another Coding Snack request? Om nom nom...

see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #10 on: August 06, 2012, 12:51:44 AM »

That's interesting. In Win7-64, the "NET" command only has these options - i.e., no RESTART:

You should be able to string it all together in one command like this: net stop <servicename> && net start <servicename>
Logged

Stoic Joker
Honorary Member
**
Posts: 5,326



View Profile WWW Give some DonationCredits to this forum member
« Reply #11 on: August 06, 2012, 06:34:26 AM »

That's interesting. In Win7-64, the "NET" command only has these options - i.e., no RESTART:

That probably has much to do with my not being a morning person, and it not actually existing.
Logged
IainB
Supporting Member
**
Posts: 4,790


Slartibartfarst

see users location on a map View Profile Give some DonationCredits to this forum member
« Reply #12 on: August 06, 2012, 08:04:34 AM »

That's interesting. In Win7-64, the "NET" command only has these options - i.e., no RESTART:
That probably has much to do with my not being a morning person, and it not actually existing.
Ahahaha! I see. I thought it was a feature in XP that must have been removed in Win7-64. I was developing "XP-envy"!
Logged
Pages: [1]   Go Up
  Reply  |  New Topic  |  Print  
 
Jump to:  
   Forum Home   Thread Marks Chat! Downloads Search Login Register  

DonationCoder.com | About Us
DonationCoder.com Forum | Powered by SMF
[ Page time: 0.327s | Server load: 0.16 ]