topbanner_forum
  *

avatar image

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

Login with username, password and session length
  • Friday December 13, 2024, 3:33 am
  • Proudly celebrating 15+ 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 8467 times)

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,940
    • View Profile
    • Donate to Member
Activate/deactive a windows service with a script
« on: August 04, 2012, 08:09 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: 6,649
    • View Profile
    • Donate to Member
Re: Activate/deactive a windows service with a script
« Reply #1 on: August 04, 2012, 08:19 AM »
net stop [service name]
net start [service name]
net restart [service name]

AbteriX

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 1,149
    • View Profile
    • Donate to Member
Re: Activate/deactive a windows service with a script
« Reply #2 on: August 04, 2012, 09:03 AM »
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

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

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

Shades

  • Member
  • Joined in 2006
  • **
  • Posts: 2,939
    • View Profile
    • Donate to Member
Re: Activate/deactive a windows service with a script
« Reply #4 on: August 04, 2012, 05:40 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: 6,649
    • View Profile
    • Donate to Member
Re: Activate/deactive a windows service with a script
« Reply #5 on: August 05, 2012, 09:22 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 PM »
I have two batch files to turn on and off 2 services:
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,645
    • View Profile
    • Donate to Member
Re: Activate/deactive a windows service with a script
« Reply #7 on: August 05, 2012, 11:24 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

sc config wuauserv start= disabled

But not:

sc config wuauserv start = disabled
sc config wuauserv start=disabled

IainB

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 7,544
  • @Slartibartfarst
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: Activate/deactive a windows service with a script
« Reply #8 on: August 06, 2012, 12:07 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 AM by IainB, Reason: Minor correction. »

IainB

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 7,544
  • @Slartibartfarst
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: Activate/deactive a windows service with a script
« Reply #9 on: August 06, 2012, 12:32 AM »
I have two batch files to turn on and off 2 services:
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: 5,287
    • View Profile
    • Donate to Member
Re: Activate/deactive a windows service with a script
« Reply #10 on: August 06, 2012, 12:51 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: 6,649
    • View Profile
    • Donate to Member
Re: Activate/deactive a windows service with a script
« Reply #11 on: August 06, 2012, 06: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.

IainB

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 7,544
  • @Slartibartfarst
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: Activate/deactive a windows service with a script
« Reply #12 on: August 06, 2012, 08:04 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"!