Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • September 03, 2015, 03:53:54 AM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Activate/deactive a windows service with a script  (Read 2971 times)

Contro

  • Participant
  • Joined in 2007
  • *
  • default avatar
  • Posts: 2,453
    • View Profile
    • Donate to Member
Activate/deactive a windows service with a script
« 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

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 5,879
    • View Profile
    • www.StoicJoker.com
    • Donate to Member
Re: Activate/deactive a windows service with a script
« Reply #1 on: August 04, 2012, 08:19:16 AM »
net stop [service name]
net start [service name]
net restart [service name]

AbteriX

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 1,085
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: Activate/deactive a windows service with a script
« 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>...

Contro

  • Participant
  • Joined in 2007
  • *
  • default avatar
  • Posts: 2,453
    • View Profile
    • Donate to Member
Re: Activate/deactive a windows service with a script
« Reply #3 on: August 04, 2012, 10:19:32 AM »
 :-[

Trying. i will comment. Are bat files ?¿
 :-*

Shades

  • Member
  • Joined in 2006
  • **
  • Posts: 1,855
    • View Profile
    • Donate to Member
Re: Activate/deactive a windows service with a script
« 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'.

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 5,879
    • View Profile
    • www.StoicJoker.com
    • Donate to Member
Re: Activate/deactive a windows service with a script
« Reply #5 on: August 05, 2012, 09:22:28 AM »
^Very good point^  :Thmbsup:

AndyM

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 616
    • View Profile
    • Donate to Member
Re: Activate/deactive a windows service with a script
« Reply #6 on: August 05, 2012, 01:53:39 PM »
I have two batch files to turn on and off 2 services:
Code: [Select]
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.

mwb1100

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,430
    • View Profile
    • Donate to Member
Re: Activate/deactive a windows service with a script
« 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

Code: [Select]
sc config wuauserv start= disabled

But not:

Code: [Select]
sc config wuauserv start = disabled
sc config wuauserv start=disabled

IainB

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 5,432
  • Slartibartfarst
    • View Profile
    • Donate to Member
Re: Activate/deactive a windows service with a script
« 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:

Command NET options.png
« Last Edit: August 06, 2012, 12:15:43 AM by IainB, Reason: Minor correction. »

IainB

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 5,432
  • Slartibartfarst
    • View Profile
    • Donate to Member
Re: Activate/deactive a windows service with a script
« Reply #9 on: August 06, 2012, 12:32:13 AM »
I have two batch files to turn on and off 2 services:
Code: [Select]
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.

Command SC options.png

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 4,393
    • View Profile
    • Donate to Member
Re: Activate/deactive a windows service with a script
« 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>

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 5,879
    • View Profile
    • www.StoicJoker.com
    • Donate to Member
Re: Activate/deactive a windows service with a script
« 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.

IainB

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 5,432
  • Slartibartfarst
    • View Profile
    • Donate to Member
Re: Activate/deactive a windows service with a script
« 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"!