Prevent a service from starting up without disabling it?


  1. Posts : 84
    Windows 7 Ultimate x64 SP1
       #1

    Prevent a service from starting up without disabling it?


    Is there a way to prevent a service from starting up without disabling it completely. I want to be able to start/stop a service by using a .bat shortcut, but that doesn't seem to work if it's disabled. If I set to Manual, the service auto starts with startup. The service is "Function Discovery Resource Publication" - FDResPub.
      My Computer


  2. Posts : 630
    Windows 10 Pro 64 bit
       #2

    There are some good suggestions here Stop and Start a service via batch or cmd file?
      My Computer


  3. Posts : 84
    Windows 7 Ultimate x64 SP1
    Thread Starter
       #3

    Lance1 said:
    There are some good suggestions here Stop and Start a service via batch or cmd file?
    well thanks, but nothing there answers my question.

    -is it possible to start a service from a .bat if it's been disabled?
    -is there a way to prevent a service from running on startup without disabling it?
      My Computer


  4. Posts : 630
    Windows 10 Pro 64 bit
       #4

    -is it possible to start a service from a .bat if it's been disabled? NO

    -is there a way to prevent a service from running on startup without disabling it? NO

    That's the brunt of it.
      My Computer


  5. Posts : 2,497
    Windows 7 Pro 64 bit
       #5

    Whenever something is as difficult as this a reasonable question is: Why do you wish to do this?
    What are you trying to accomplish that requires such an unusual service configuration?
    Maybe there is a better way.
      My Computer


  6. Posts : 84
    Windows 7 Ultimate x64 SP1
    Thread Starter
       #6

    Got it. Looks like it's a 2-step process. stop>disable>enable>start. This makes it pointless to run from a batch as it's just qucker to open a shortcut to services.msc and change the settings from there.

    thanks.
      My Computer


  7. Posts : 84
    Windows 7 Ultimate x64 SP1
    Thread Starter
       #7

    LMiller7 said:
    Whenever something is as difficult as this a reasonable question is: Why do you wish to do this?
    What are you trying to accomplish that requires such an unusual service configuration?
    Maybe there is a better way.
    Simply, there's a service which I don't want to run on startup. I want to control when it runs it manually. I thought (wrongly) that setting the service to 'manual' would accomplish this. Instead it turns out I need to stop the service, then disable it This means it is a 2-step process to start it again also.

    Is manually controlling a service really such an "unusual configuration"?
      My Computer


  8. Posts : 5,092
    Windows 7 32 bit
       #8

    I would think you could set the start type using SC command in batch, then run a delay to give it time to kick in. Then run the command to start it. Play around with sc.exe.

    https://technet.microsoft.com/en-us/.../bb490995.aspx

    Setting the delay in batch

    4 Ways to Delay a Batch File - wikiHow
      My Computer


  9. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #9

    sleepless said:
    -is it possible to start a service from a .bat if it's been disabled?
    -is there a way to prevent a service from running on startup without disabling it?
    No and no. But that doesn't mean there isn't a solution.

    Triggering a service while its start mode is set to Disabled can be achieved by quickly setting the start mode to Enabled, starting the service, then Disabling the service again in quick succession. This'll work because, a disabled service cannot be started, however, a service that is disabled while it is running will continue to run until manually stopped.

    E.g., assume the disabled service "RemoteRegistry". This service can be started using the below example batch file
    Code:
    @echo off
    REM Starts a disabled service by first enabling it, starting it, then disabling it again.
    REM Some services may require Run As Administrator to start.
     
    REM Tested the script with 'RemoteRegistry' service.
    set "service=RemoteRegistry"
    REM Stop script execution if the service's start mode is not currently disabled
    sc qc "%SERVICE%" | find "START_TYPE" | find "4" >NUL || (echo Start mode of given service is not disabled& exit /b 1)
    REM Stop script execution if the service is already runnning
    sc query "%SERVICE%" | find "STATE" | find "4" >NUL && (echo Service is already running& exit /b 1)
    REM Set start mode of service to Manual
    sc config "%SERVICE%" start=demand
    REM Start the service
    sc start "%SERVICE%"
    REM Set service start mode back to Disabled
    sc config "%SERVICE%" start=disabled

    sleepless said:
    [...] This makes it pointless to run from a batch as it's just qucker to open a shortcut to services.msc and change the settings from there.
    I highly doubt the efficiency of your clicking competes with a script.

    sleepless said:
    I want to control when [the service] runs it manually. I thought (wrongly) that setting the service to 'manual' would accomplish this.
    Ditto. There must a process explicitly requesting that your service be started. It's tricky to tell which process this is, and even then there is no way to prevent it from doing so.

    sleepless said:
    Is manually controlling a service really such an "unusual configuration"?
    Depending on your goal; there may be a more optimal method.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 00:55.
Find Us