Stop two cantankerous services with a batch file


  1. Posts : 843
    11 Pro 21H2 (22000.832)
       #1

    Stop two cantankerous services with a batch file


    I have two stubborn services that slow down my shutdowns and reboots: the Macrium service, which I can stop and change to manual startup if I'm in the Services panel, but not from a command prompt or with a batch (and the service resets to automatic start every time the program updates), and the MBAM service, which I can't stop either remotely (with service-name or PID) or in the Services panel (Access denied), but it has a program icon in the tray with a right-click option to "Quit Malwarebytes," and what that switch does (exactly and only, as far as I can tell) is stop the MBAM service.

    SO, if I use the switch in the MBAM right-click menu AND open the services panel and find and stop the Macrium service, I get shutdowns and reboots that are about seven or eight or ten seconds faster. But it takes much more than ten seconds to flick the tray icon switch and open the services panel and navigate to Macrium and stop it, and then activate my shutdown shortcut

    Anybody have a notion how I can phrase a batch that will shut down both of these services pre-shutdown? I shut down my machine every time I'm going to be away from it for more than about an hour, so if I can pull off what I want to pull off, it'll save me a few minutes a month (and at my age, minutes are valuable things).

    Now, as all of you experts can tell, this is not a very high-priority question. There are no fires to put out here. But if you happen to know of a solution, and you have a few (valuable) minutes to commit to the writing up of that solution, I'd be forever grateful for your kindness. Well, maybe not forever, but for a few (valuable) minutes, anyway.

    Wisewiz Win 10 1909
      My Computers


  2. Posts : 4,187
    Windows 11 Pro, 22H2
       #2

    1) Run services.msc. Locate the services that you want to stop.
    2) Right-click the service and select Properties.
    3) Note the service name (NOT the display name).
    4) Create a batch file with the command "net stop service_name".
    Example: net stop macriumservice

    When tou run the batch file, it must be run elevated (right-click, run as administrator).
      My Computers


  3. Posts : 4,187
    Windows 11 Pro, 22H2
       #3

    If you want to get fancier, try this code (explanation follows the code):

    Code:
    @echo off
    
    REM Change to directory where the batch file is located.
    cd /d %~dp0
    
    
    REM Check to see if this batch file is being run as Administrator
    
    openfiles > NUL 2>&1 
    if NOT %ERRORLEVEL% EQU 0 goto NotAdmin 
    goto IsAdmin
    
       :NotAdmin
    
    REM The batch file was not run as admin. Launch a new copy of the batch file as admin and close the current instance.
    
    powershell.exe start-process '%~f0' -verb runas
    exit
    
       :IsAdmin
    
    REM End Routine to check if being run as Admin
    
    
    REM Stop the macrium service
    
    net stop macriumservice
    
    
    REM End program
       :END
    This is an example of a self-elevating batch file. The purpose of the above code is to avoid you having to remember to run the batch file as admin. If you simply double-click the batch file to run it, it will check to see if it is being run as admin. If not, it will automatically re-launch itself as admin and terminate the original instance.

    The above example will stop the macrium service. If you have more services that you wish to stop, simply place additional "net stop" commands right after that one.

    I hope this helps!

    Please let me know if this works as you wished.
      My Computers


  4. Posts : 843
    11 Pro 21H2 (22000.832)
    Thread Starter
       #4

    Oh, man, I really appreciate this. I thought I had thoroughly tested both the "net stop Macriumservice" and the "taskkill /PID 2016 /f" batches, but I guess I hadn't. Your suggestion made me try again, and the net stop thing worked, both when I right-clicked the batch itself and chose Run as Admin, and when I made a shortcut (so that I could hotkey it) and checked Run as Admin in the Properties of the shortcut. (And by the way, I'm not sure what the difference is between those two approaches, but I think I've read somewhere that there IS a difference.)

    Anyway, I'm left with trying to figure out why I can't force the anti-malware program to stop with a batch, but it stops immediately when I click the "Quit Malwarebytes" switch in the system tray icon. I wish I could figure out what functions that switch calls. I wrote to Malwarebytes a while back, and got only a curt "Please don't mess with the program" or words to that effect.

    Thank you for taking the time to help.

    - - - Updated - - -

    Just a small P.S. to my previous posts: I was using this bat script successfully in W7Pro, but it no longer has the desired effect:

    @echo off
    net stop MacriumService
    sc config MacriumService start= demand
    exit

    In fact, it seems to have no effect at all on the service. It doesn't stop, and it doesn't change from automatic to manual.
    The first line by itself works. What's wrong with the second line? Ideas?
      My Computers


  5. Posts : 4,187
    Windows 11 Pro, 22H2
       #5

    Don't know why those commands were not working for you. They work fine for me - again, making sure I have admin rights.

    As for malwarebytes, it's not something that I use, but maybe someone else who uses will have ideas on that topic.
      My Computers


  6. Posts : 843
    11 Pro 21H2 (22000.832)
    Thread Starter
       #6

    Thank you very much for your help. I'll keep at it until it's working.
      My Computers


 

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

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




Windows 10 Forums