How to make a batch file on starting and stopping services from command prompt ?

VistaKing

Banned
does anyone know how to make a batch file where you could start ,disable , stop and manual for a service from the command prompt ?

for example instead of going to services.msc and right clicking on a service then clicking on properties then making the startup to be manual,automatic or disable . I could do with a batch file where i would just launch the batch file and it would make the startup to manual and then disable the service that i want to disable.
 

My Computer

Aside from the obvious, what is it you're trying to accomplish? What services do you want disabled at one time but not another?
 

My Computer

System One

  • Manufacturer/Model
    Fumz' Flux-Capacitor
    CPU
    E8400
    Motherboard
    DFI LP DK P35-T2RS
    Memory
    4GB G.Skill PC-1066
    Graphics Card(s)
    eVGA 8800 GTS
    Sound Card
    X-Fi XtremeGamer
    Monitor(s) Displays
    Samsung 226BW
    Screen Resolution
    1680x1050
    Hard Drives
    500GB W.D. RE2 Primary
    1TB W.D. Caviar GP WD10EACS
    PSU
    PC Power & Cooling Silencer 610
    Case
    Lian Li Lancool K62
    Cooling
    Thermalright Ultima-90/S-Flex 120mm
    Keyboard
    MS Natural Elite 4000 Ergonomic
    Mouse
    Logitech G5
    Internet Speed
    2.5MB/430
    Other Info
    D-Link DGL 4500
net start <service name>

net stop <service name>
 

My Computers

System One System Two

  • Operating System
    Windows 11 Workstation
    Manufacturer/Model
    doofenshmirtz evil incorporated
    CPU
    Ryzen 9 5950X
    Motherboard
    Asus ROG Crosshair VIII Formula
    Memory
    Corsair Vengeance RGB PRO Black 64GB (4x16GB) 3600MHz AMD Ryzen Tuned DDR4
    Graphics Card(s)
    ASUS AMD Radeon RX 6900 XT 16GB ROG Strix LC OC
    Sound Card
    Creative
    Monitor(s) Displays
    3 x27" Dell U2724D & 1 x 34" Dell U3415W
    Hard Drives
    Samsung 980 Pro 1TB M.2 2280 PCI-e 4.0 x4 NVMe Solid State
    Drive
    PSU
    1500W ThermalTake Toughpower
    Case
    ThermalTake Level 10 GT
    Cooling
    Enermax Liqtech 240
    Keyboard
    Surface Ergonomic.
    Mouse
    Logitech Performance MX
    Internet Speed
    350 Mb/s
    Other Info
    WinTV NovaTD
    HP CP1515n Color Laser
    Sony BD-5300S-0B Blu-ray Writer
    Microsoft LifeCam Cinema
    APC 750i Smart UPS
  • Operating System
    windows 10
    Manufacturer/Model
    Surface Pro 3
    CPU
    1.9GHz Intel Core i5-4300U (dual-core, 3MB cache, up to 2.9GHz with Turbo Boost)
    Memory
    4GB
    Graphics card(s)
    Intel HD Graphics 4400
    Monitor(s) Displays
    12" Multi Touch
    Screen Resolution
    2160 x 144
    Hard Drives
    128GB
    Mouse
    Logitech
    Keyboard
    yes
    Internet Speed
    350 Mb/s
I want to know how I could make a service start manually or autmatically or disable from a command prompt by making a batch file. Instead of right-clicking on a service then going to properties and then click on the down arrow on startup and point to "automatic,disable or manual". Its for work. I know about net start " service name " and net stop " service name " . I'm trying to have it where it disables a service and I could make it manual instead of automatic from the batch file.
 

My Computer

My Computers

System One System Two

  • Operating System
    Windows 10 Pro X64 Insider Preview (Skip Ahead) latest build
    Manufacturer/Model
    The Beast Model V (homebrew)
    CPU
    Intel Core i7 965 EE @ 3.6 GHz
    Motherboard
    eVGA X58 Classified 3 (141-GT-E770-A1)
    Memory
    3 * Mushkin 998981 Redline Enhanced triple channel DDR3 4 GB CL7 DDR3 1600 MHz (PC3-12800)
    Graphics Card(s)
    eVGA GeForce GTX 970 SSC ACX 2.0 (04G-P4-3979-KB)
    Sound Card
    Realtek HD Audio (onboard)
    Monitor(s) Displays
    2 * Lenovo LT2323pwA Widescreeen
    Screen Resolution
    2 * 1920 x 1080
    Hard Drives
    SanDisk Ultra SDSSDHII-960G-G25 960 GB SATA III SSD (System)
    Crucial MX100 CT256MX100SSD1 256GB SATA III SSD (User Tree)
    2 * Seagate Barracuda 7200.12 ST31000528AS 1TB 7200 RPM SATA II Mech. HD
    Seagate ST1500DL001-9VT15L Barracuda 7200.12 1.5 TB S
    PSU
    Thermaltake Black Widow TX TR2 850W 80+ Bronze Semi-Mod ATX
    Case
    ThermalTake Level 10 GT (Black)
    Cooling
    Corsair H100 (CPU, dual 140 mm fans on radiator) + Air (2 *
    Keyboard
    Logitech G15 (gen 2)
    Mouse
    Logitech MX Master (shared)
    Internet Speed
    AT&T Lightspeed Gigabit duplex
  • Operating System
    Sabayon Linux (current, weekly updates, 5.1.x kernel)
    Manufacturer/Model
    Lenovo ThinkPad E545
    CPU
    AMD A6-5350M APU
    Motherboard
    Lenovo
    Memory
    8 GB
    Graphics card(s)
    Radeon HD (Embedded)
    Sound Card
    Conextant 20671 SmartAudio HD
    Monitor(s) Displays
    Lenovo 15" Matte
    Screen Resolution
    1680 * 1050
    Hard Drives
    INTEL Cherryvill 520 Series SSDSC2CW180A 180 GB SSD
    PSU
    Lenovo
    Case
    Lenovo
    Cooling
    Lenovo
    Mouse
    Logitech MX Master (shared) | Synaptics TouchPad
    Keyboard
    Lenovo
    Internet Speed
    AT&T LightSpeed Gigabit Duplex
Seriously, I want to learn something here. I understand what you're trying to do, but what I want to know is why? What are the practical applications of doing this?
 

My Computer

System One

  • Manufacturer/Model
    Fumz' Flux-Capacitor
    CPU
    E8400
    Motherboard
    DFI LP DK P35-T2RS
    Memory
    4GB G.Skill PC-1066
    Graphics Card(s)
    eVGA 8800 GTS
    Sound Card
    X-Fi XtremeGamer
    Monitor(s) Displays
    Samsung 226BW
    Screen Resolution
    1680x1050
    Hard Drives
    500GB W.D. RE2 Primary
    1TB W.D. Caviar GP WD10EACS
    PSU
    PC Power & Cooling Silencer 610
    Case
    Lian Li Lancool K62
    Cooling
    Thermalright Ultima-90/S-Flex 120mm
    Keyboard
    MS Natural Elite 4000 Ergonomic
    Mouse
    Logitech G5
    Internet Speed
    2.5MB/430
    Other Info
    D-Link DGL 4500
Simple - an easy way to disable services - some services are in automatic mode and will auto start themselves even if you stop them - Indexing for example.
 

My Computers

System One System Two

  • Operating System
    Windows 10 Pro X64 Insider Preview (Skip Ahead) latest build
    Manufacturer/Model
    The Beast Model V (homebrew)
    CPU
    Intel Core i7 965 EE @ 3.6 GHz
    Motherboard
    eVGA X58 Classified 3 (141-GT-E770-A1)
    Memory
    3 * Mushkin 998981 Redline Enhanced triple channel DDR3 4 GB CL7 DDR3 1600 MHz (PC3-12800)
    Graphics Card(s)
    eVGA GeForce GTX 970 SSC ACX 2.0 (04G-P4-3979-KB)
    Sound Card
    Realtek HD Audio (onboard)
    Monitor(s) Displays
    2 * Lenovo LT2323pwA Widescreeen
    Screen Resolution
    2 * 1920 x 1080
    Hard Drives
    SanDisk Ultra SDSSDHII-960G-G25 960 GB SATA III SSD (System)
    Crucial MX100 CT256MX100SSD1 256GB SATA III SSD (User Tree)
    2 * Seagate Barracuda 7200.12 ST31000528AS 1TB 7200 RPM SATA II Mech. HD
    Seagate ST1500DL001-9VT15L Barracuda 7200.12 1.5 TB S
    PSU
    Thermaltake Black Widow TX TR2 850W 80+ Bronze Semi-Mod ATX
    Case
    ThermalTake Level 10 GT (Black)
    Cooling
    Corsair H100 (CPU, dual 140 mm fans on radiator) + Air (2 *
    Keyboard
    Logitech G15 (gen 2)
    Mouse
    Logitech MX Master (shared)
    Internet Speed
    AT&T Lightspeed Gigabit duplex
  • Operating System
    Sabayon Linux (current, weekly updates, 5.1.x kernel)
    Manufacturer/Model
    Lenovo ThinkPad E545
    CPU
    AMD A6-5350M APU
    Motherboard
    Lenovo
    Memory
    8 GB
    Graphics card(s)
    Radeon HD (Embedded)
    Sound Card
    Conextant 20671 SmartAudio HD
    Monitor(s) Displays
    Lenovo 15" Matte
    Screen Resolution
    1680 * 1050
    Hard Drives
    INTEL Cherryvill 520 Series SSDSC2CW180A 180 GB SSD
    PSU
    Lenovo
    Case
    Lenovo
    Cooling
    Lenovo
    Mouse
    Logitech MX Master (shared) | Synaptics TouchPad
    Keyboard
    Lenovo
    Internet Speed
    AT&T LightSpeed Gigabit Duplex
Johngalt,
SC? What I'm trying to do is from the command prompt(cmd) is to make a service manual then disable it then start it again. I want that as a batch file .So when I run the batch file thats what it does. If you can tell me how that would be great.
 

My Computer

Did you bother to read that link?

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


        The option <server> has the form "\\ServerName"
        Further help on commands can be obtained by typing: "sc [command]"
        Commands:
          query-----------Queries the status for a service, or
                          enumerates the status for types of services.
          queryex---------Queries the extended status for a service, or
                          enumerates the status for types of services.
          start-----------Starts a service.
          pause-----------Sends a PAUSE control request to a service.
          interrogate-----Sends an INTERROGATE control request to a service.
          continue--------Sends a CONTINUE control request to a service.
          stop------------Sends a STOP request to a service.
          config----------Changes the configuration of a service (persistent).
          description-----Changes the description of a service.
          failure---------Changes the actions taken by a service upon failure.
          failureflag-----Changes the failure actions flag of a service.
          sidtype---------Changes the service SID type of a service.
          privs-----------Changes the required privileges of a service.
          qc--------------Queries the configuration information for a service.
          qdescription----Queries the description for a service.
          qfailure--------Queries the actions taken by a service upon failure.
          qfailureflag----Queries the failure actions flag of a service.
          qsidtype--------Queries the service SID type of a service.
          qprivs----------Queries the required privileges of a service.
          delete----------Deletes a service (from the registry).
          create----------Creates a service. (adds it to the registry).
          control---------Sends a control to a service.
          sdshow----------Displays a service's security descriptor.
          sdset-----------Sets a service's security descriptor.
          showsid---------Displays the service SID string corresponding to an arbitrary name.
          GetDisplayName--Gets the DisplayName for a service.
          GetKeyName------Gets the ServiceKeyName for a service.
          EnumDepend------Enumerates Service Dependencies.

        The following commands don't require a service name:
        sc <server> <command> <option>
          boot------------(ok | bad) Indicates whether the last boot should
                          be saved as the last-known-good boot configuration
          Lock------------Locks the Service Database
          QueryLock-------Queries the LockStatus for the SCManager Database
EXAMPLE:
        sc start MyService

Would you like to see help for the QUERY and QUERYEX commands? [ y | n ]:
 

My Computers

System One System Two

  • Operating System
    Windows 10 Pro X64 Insider Preview (Skip Ahead) latest build
    Manufacturer/Model
    The Beast Model V (homebrew)
    CPU
    Intel Core i7 965 EE @ 3.6 GHz
    Motherboard
    eVGA X58 Classified 3 (141-GT-E770-A1)
    Memory
    3 * Mushkin 998981 Redline Enhanced triple channel DDR3 4 GB CL7 DDR3 1600 MHz (PC3-12800)
    Graphics Card(s)
    eVGA GeForce GTX 970 SSC ACX 2.0 (04G-P4-3979-KB)
    Sound Card
    Realtek HD Audio (onboard)
    Monitor(s) Displays
    2 * Lenovo LT2323pwA Widescreeen
    Screen Resolution
    2 * 1920 x 1080
    Hard Drives
    SanDisk Ultra SDSSDHII-960G-G25 960 GB SATA III SSD (System)
    Crucial MX100 CT256MX100SSD1 256GB SATA III SSD (User Tree)
    2 * Seagate Barracuda 7200.12 ST31000528AS 1TB 7200 RPM SATA II Mech. HD
    Seagate ST1500DL001-9VT15L Barracuda 7200.12 1.5 TB S
    PSU
    Thermaltake Black Widow TX TR2 850W 80+ Bronze Semi-Mod ATX
    Case
    ThermalTake Level 10 GT (Black)
    Cooling
    Corsair H100 (CPU, dual 140 mm fans on radiator) + Air (2 *
    Keyboard
    Logitech G15 (gen 2)
    Mouse
    Logitech MX Master (shared)
    Internet Speed
    AT&T Lightspeed Gigabit duplex
  • Operating System
    Sabayon Linux (current, weekly updates, 5.1.x kernel)
    Manufacturer/Model
    Lenovo ThinkPad E545
    CPU
    AMD A6-5350M APU
    Motherboard
    Lenovo
    Memory
    8 GB
    Graphics card(s)
    Radeon HD (Embedded)
    Sound Card
    Conextant 20671 SmartAudio HD
    Monitor(s) Displays
    Lenovo 15" Matte
    Screen Resolution
    1680 * 1050
    Hard Drives
    INTEL Cherryvill 520 Series SSDSC2CW180A 180 GB SSD
    PSU
    Lenovo
    Case
    Lenovo
    Cooling
    Lenovo
    Mouse
    Logitech MX Master (shared) | Synaptics TouchPad
    Keyboard
    Lenovo
    Internet Speed
    AT&T LightSpeed Gigabit Duplex
Did you bother to read that link?

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


        The option <server> has the form "\\ServerName"
        Further help on commands can be obtained by typing: "sc [command]"
        Commands:
          query-----------Queries the status for a service, or
                          enumerates the status for types of services.
          queryex---------Queries the extended status for a service, or
                          enumerates the status for types of services.
          start-----------Starts a service.
          pause-----------Sends a PAUSE control request to a service.
          interrogate-----Sends an INTERROGATE control request to a service.
          continue--------Sends a CONTINUE control request to a service.
          stop------------Sends a STOP request to a service.
          config----------Changes the configuration of a service (persistent).
          description-----Changes the description of a service.
          failure---------Changes the actions taken by a service upon failure.
          failureflag-----Changes the failure actions flag of a service.
          sidtype---------Changes the service SID type of a service.
          privs-----------Changes the required privileges of a service.
          qc--------------Queries the configuration information for a service.
          qdescription----Queries the description for a service.
          qfailure--------Queries the actions taken by a service upon failure.
          qfailureflag----Queries the failure actions flag of a service.
          qsidtype--------Queries the service SID type of a service.
          qprivs----------Queries the required privileges of a service.
          delete----------Deletes a service (from the registry).
          create----------Creates a service. (adds it to the registry).
          control---------Sends a control to a service.
          sdshow----------Displays a service's security descriptor.
          sdset-----------Sets a service's security descriptor.
          showsid---------Displays the service SID string corresponding to an arbitrary name.
          GetDisplayName--Gets the DisplayName for a service.
          GetKeyName------Gets the ServiceKeyName for a service.
          EnumDepend------Enumerates Service Dependencies.

        The following commands don't require a service name:
        sc <server> <command> <option>
          boot------------(ok | bad) Indicates whether the last boot should
                          be saved as the last-known-good boot configuration
          Lock------------Locks the Service Database
          QueryLock-------Queries the LockStatus for the SCManager Database
EXAMPLE:
        sc start MyService

Would you like to see help for the QUERY and QUERYEX commands? [ y | n ]:

John,
Yes I did. Still stuck on how I would go about writing a .bat file so when I launch the .bat file. It makes a service to manual in the startup choice then disables it then starts it. By the way how did you get the entire thing from command prompt to show up from the SC /? I type that and it goes down but doesn't show me the top portion.
 

My Computer

Aha - I think you (johngalt) have answered the question(s) I ask in Batch Job How to? Thank you!
 

My Computer

System One

  • CPU
    INTEL CORE 2DUO CPU T5250
    Motherboard
    MOBILE INTEL 965 EXPRESS CHIPS
    Memory
    2.00 GB
    Graphics Card(s)
    (n/a) 800x600 (1Hz)
    Hard Drives
    FUJITSU MHW2160BH PL
Glad it helped you, VMLENZA.

VistaKing, writing a batch job would be simple enough - since SC is a commandline option, you'd use it in a batch file like any other command line in a batch file:

Code:
sc <servername> [command] [service name] <option1> <options 2> ...

Doing that you'd have to know the service name. If you won't know the service name prior to execution, write the batch file as follows:

Code:
sc <servername> [command] %1 <option1> <options 2> ...

and save it as a batch file in a directory that is included in your path. To find out the directories that are a part of your path, type
Code:
path
and it will list your current path.

If you want to store it in a new directory, and append that directory to your path, go to Control Panel --> System and Maintenance --> System, then click Advanced system settings on the left hand side (if you have UAC enabled, you'll need to grant elevated privileges by clicking the Continue button) and the click the Environment Variables... button. In the top section you can add your directory to the path for your user only, and in the bottom section you can add the directory to the system path (meaning it will be in the path for *all* users).

Now, you can just run it from the CMD window or a Run dialog by entering
Code:
sc {servicename}
and that batch file will run that command with whatever parameters you have set in the batch file.

now, to make it truly interactive, you'd have to do some fancy footwork using choice and wait / pause commands, but you get the general idea.
 

My Computers

System One System Two

  • Operating System
    Windows 10 Pro X64 Insider Preview (Skip Ahead) latest build
    Manufacturer/Model
    The Beast Model V (homebrew)
    CPU
    Intel Core i7 965 EE @ 3.6 GHz
    Motherboard
    eVGA X58 Classified 3 (141-GT-E770-A1)
    Memory
    3 * Mushkin 998981 Redline Enhanced triple channel DDR3 4 GB CL7 DDR3 1600 MHz (PC3-12800)
    Graphics Card(s)
    eVGA GeForce GTX 970 SSC ACX 2.0 (04G-P4-3979-KB)
    Sound Card
    Realtek HD Audio (onboard)
    Monitor(s) Displays
    2 * Lenovo LT2323pwA Widescreeen
    Screen Resolution
    2 * 1920 x 1080
    Hard Drives
    SanDisk Ultra SDSSDHII-960G-G25 960 GB SATA III SSD (System)
    Crucial MX100 CT256MX100SSD1 256GB SATA III SSD (User Tree)
    2 * Seagate Barracuda 7200.12 ST31000528AS 1TB 7200 RPM SATA II Mech. HD
    Seagate ST1500DL001-9VT15L Barracuda 7200.12 1.5 TB S
    PSU
    Thermaltake Black Widow TX TR2 850W 80+ Bronze Semi-Mod ATX
    Case
    ThermalTake Level 10 GT (Black)
    Cooling
    Corsair H100 (CPU, dual 140 mm fans on radiator) + Air (2 *
    Keyboard
    Logitech G15 (gen 2)
    Mouse
    Logitech MX Master (shared)
    Internet Speed
    AT&T Lightspeed Gigabit duplex
  • Operating System
    Sabayon Linux (current, weekly updates, 5.1.x kernel)
    Manufacturer/Model
    Lenovo ThinkPad E545
    CPU
    AMD A6-5350M APU
    Motherboard
    Lenovo
    Memory
    8 GB
    Graphics card(s)
    Radeon HD (Embedded)
    Sound Card
    Conextant 20671 SmartAudio HD
    Monitor(s) Displays
    Lenovo 15" Matte
    Screen Resolution
    1680 * 1050
    Hard Drives
    INTEL Cherryvill 520 Series SSDSC2CW180A 180 GB SSD
    PSU
    Lenovo
    Case
    Lenovo
    Cooling
    Lenovo
    Mouse
    Logitech MX Master (shared) | Synaptics TouchPad
    Keyboard
    Lenovo
    Internet Speed
    AT&T LightSpeed Gigabit Duplex
This is the code that i use within a batch file to interrgogate (check the status) of a specific service.

Echo Interrogating phxctmspfs01
echo off
sc \\phxctmspfs01 interrogate fnfdashboardagent
pause

After interrogating the service it pauses. You can add the additional responses to a menu to run at that point to stop or start the service. Keep in mind that the SC command doesnot have a restart command.
 

My Computer

I think what Fumz is trying to get at is - OK, it's easy to see why you might want to turn a service on or off, but why do you want to change the startup profile of the service programmatically? If you have services A, B, C you may want to interact with in realtime, is it so hard to just go in ahead of time, change them to Manual, and just ... leave them that way? Surely the set of services you need to manipulate in this way is not indeterminate, which would be the main reason for a programmatic approach?
 

My Computer

System One

  • CPU
    Intel Q6600 o/c 3GHz
    Motherboard
    GA-P35-DS3P
    Memory
    4 GHz
    Hard Drives
    4 x 250GB Hitachi
I think what Fumz is trying to get at is - OK, it's easy to see why you might want to turn a service on or off, but why do you want to change the startup profile of the service programmatically? If you have services A, B, C you may want to interact with in realtime, is it so hard to just go in ahead of time, change them to Manual, and just ... leave them that way? Surely the set of services you need to manipulate in this way is not indeterminate, which would be the main reason for a programmatic approach?

Not everyone sits in front of the machine interactively using GUIs. Say for example you are a system administrator on a network of PCs and you want to change settings on 100 machines. Takes a long time to get on a plane to another city, log in, and use the GUI.
 

My Computer

System One

  • Manufacturer/Model
    HP Pavilion m9515y
    CPU
    Phenom X4 9850
    Memory
    8 GB
    Graphics Card(s)
    Some Radeon Cheapie with 512 MB Ram
    Monitor(s) Displays
    CRT
    Screen Resolution
    1280x1024
    Hard Drives
    750 GB SATA 3G
    2 SIIG Superspeed docks w/WD Caviar Black Sata II or III
Back
Top