SOLVED A macro/shortcut to toggle one service

Ian

Administrator
Joined
Oct 27, 2013
Messages
1,736
Reaction score
630
Are you familiar with PowerShell? It would be possible to create a script to disable a service (or enable it) by running a shortcut on the desktop. You could even give it a shortcut key to run without clicking it (via the Properties menu on the desktop icon).

To stop a service run the following command:

Code:
Stop-Service ServiceName

To start a service run the following command:

Code:
Start-Service ServiceName

You can add that code to separate .PS1 files, or use the PowerShell editor to create your scripts.

There are some great tutorials in the Articles section written by @Regedit32 which explain in detail how to create your first scripts: https://www.windows10forums.com/articles/categories/powershell-tutorials.5/
 
Joined
Apr 6, 2015
Messages
323
Reaction score
10
I have heard of PowerShell, but I am not familiar with using it. However, I have written many macros and your advice sounds like creating a macro.
I would like to have an easily accessible (so on the desktop) shortcut that I could click once to turn a service ON and again once to turn it OFF. I do NOT want to use a 'key'. Learning Powershell so as to be able to create a script, seems counter productive in view of the effort involved. I have never heard of PS1 files, so or used the PowerShell editor, so your well-meant advice comes across as daunting.
 

Ian

Administrator
Joined
Oct 27, 2013
Messages
1,736
Reaction score
630
If you want a slightly easier way, create 2 files on your desktop called start.bat and end.bat (make sure that the file extension is .bat). These aren't shortcuts, but very simple scripts that will run as icons on your desktop, so they'll look the same and function when double clicking on them.

Edit the start.bat file and add the following code (where ServiceName is the name of the service you want to control):

Code:
net start ServiceName

Then edit end.bat and add:

Code:
net stop ServiceName

Once they're saved, double click one of the icons to start/stop your script. Hopefully that is a little more helpful :).
 
Joined
Apr 6, 2015
Messages
323
Reaction score
10
The method you suggest is the standard batch file method that I am VERY familiar with, and would prefer IF IT WORKED, but having manually stared the Malwarebytes Service, your code for the batch file did NOT stop the service. So either I need better code (PLEASE !) or a different method (Powershell ?)
 

Ian

Administrator
Joined
Oct 27, 2013
Messages
1,736
Reaction score
630
Lets try some troubleshooting. Can you please go to the command prompt (search for this on the start menu, or run "cmd) and try the following command - I think this should work for the MBAM service.

Code:
net stop MBAMService

Is this the same service name you used?

What reply does the command prompt give - it should let you know if it has worked, or why it has failed. The error won't appear when running via a batch file, as the window will have closed by the time it appears. This information should give us a clue :).
 
Joined
Apr 6, 2015
Messages
323
Reaction score
10
Your code did the trick, provided that I ran CMD as Administrator.
Now to get the two commands into one batchfile that will toggle MBAMService each time it is clicked.

A suggestion I got which failed, but might have valuable guidance was :

"@ECHO OFF

REM Checking Service state
net start MBAMService 2>nul
if errorlevel 2 goto AlreadyRunning
if errorlevel 1 goto Error


REM Service started

GOTO ContinueWithBatch

:AlreadyRunning
REM Service is already running
net stop MBAMService
GOTO ContinueWithBatch

:Error
REM Service failed to start
GOTO ContinueWithBatch

:ContinueWithBatch"
 

Ian

Administrator
Joined
Oct 27, 2013
Messages
1,736
Reaction score
630
Nice script - I can't see any reason why that shouldn't work.

If you could run that batch file from within the command prompt (so that it doesn't exit once it has run), do you see any error messages? You'll need to remove that first line "@ECHO OFF" so that errors are displayed.
 
Joined
Apr 6, 2015
Messages
323
Reaction score
10
I pasted all the script AFTER 'echo off' into the Command window. The status did not appear to change, but the text in the window seems to suggest that it does BOTH, instead of just one [one loop too many ?].

C:\WINDOWS\system32>REM Checking Service state

C:\WINDOWS\system32>net start MBAMService 2>nul
The Malwarebytes Service service is starting.
The Malwarebytes Service service was started successfully.


C:\WINDOWS\system32>if errorlevel 2 goto AlreadyRunning

C:\WINDOWS\system32>if errorlevel 1 goto Error

C:\WINDOWS\system32>
C:\WINDOWS\system32>
C:\WINDOWS\system32>REM Service started

C:\WINDOWS\system32>
C:\WINDOWS\system32>GOTO ContinueWithBatch

C:\WINDOWS\system32>
C:\WINDOWS\system32>:AlreadyRunning
C:\WINDOWS\system32>REM Service is already running

C:\WINDOWS\system32>net stop MBAMService
The Malwarebytes Service service is stopping.
The Malwarebytes Service service was stopped successfully.


C:\WINDOWS\system32>GOTO ContinueWithBatch

C:\WINDOWS\system32>
C:\WINDOWS\system32>:Error
C:\WINDOWS\system32>REM Service failed to start

C:\WINDOWS\system32>GOTO ContinueWithBatch

C:\WINDOWS\system32>
C:\WINDOWS\system32>:ContinueWithBatch"
 

Ian

Administrator
Joined
Oct 27, 2013
Messages
1,736
Reaction score
630
I've tried the script on my system and it works as expected. Did you save it as a .bat file initially? You'll need to run it with elevated (admin) permissions.

If you pasted it in to the command prompt, it won't work as expected unfortunately. Could you please save it as a .bat file somewhere (i.e. C:\Temp\MBAM.bat) and then type "C:\Temp\MBAM.bat" when you're at the command prompt. That should run the script in its entirely and allow you to view the error output (assuming the @ECHO OFF is removed).
 
Joined
Apr 6, 2015
Messages
323
Reaction score
10
SUCCESS - the batch file both started and stopped the MBAM service. BUT it is counterproductive, if I have to first launch an administrative command prompt and then type the batchfile name into it.
Just clicking on the batch file produces NO change - not least, I imagine, because 'as administrator' has not been invoked.
 

Ian

Administrator
Joined
Oct 27, 2013
Messages
1,736
Reaction score
630
Excellent :).

You can work around the admin permissions problem easily enough. Place the .bat file somewhere on your system and then create a shortcut to it on your desktop.

Then, right click the icon and select Properties and then click the Shortcut tab. Now click the Advanced button and check the box that says "Run as Administrator". Click ok a couple of times and you're done :).

upload_2018-3-5_13-37-15.png
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top