Page 1 of 1

Stopping a service

Posted: 03 Nov 2016, 16:50
by AHKxx
Hi. I'd like to use hotkey to stop a service, without any prompts, confirmations, etc. In W8.1. I've done a search, and have found a few theoretical solutions, but none of them are working. Everything I've tried, based on what I've found, is along these lines:

Code: Select all

^!+x::run net stop "wuauserv"  
and

Code: Select all

^!+x::RunWait, %comspec% /c net ... , , hide
These all run in a cmd window but are not stopping the service.

Anyone know how I can do this?

Thank you!

Re: Stopping a service

Posted: 03 Nov 2016, 18:47
by Masonjar13
Your second bit of code should be used. And are you running as admin?

Re: Stopping a service

Posted: 05 Nov 2016, 13:11
by RickC
I usually use sc instead of net and, as Masonjar13 points out, you need to run the script as Admin.

For example:

Code: Select all

; Prompt to 'Run as Admin', i.e. show UAC dialog
If Not A_IsAdmin
{
   Run *RunAs "%A_ScriptFullPath%"  ; Requires v1.0.92.01+
   ExitApp
}

; Stop and delete the Retail Demo service in Windows 10
RunWait,sc stop "RetailDemo",,hide
RunWait,sc config "RetailDemo" start= disabled,,hide
RunWait,sc delete "RetailDemo",,hide

Re: Stopping a service

Posted: 08 Nov 2016, 12:20
by AHKxx
Thanks for these replies!

Am I running as admin? I'm signed in with full admin privileges, but I'm not running AHK or this particular script "as Admin", at least not explicitly.

I will try out the above suggestions, and update results!

I want to easily shut down windows update in W8.1, which has started running frequently and will run for hours before finally doing anything. I've been manually stopping the service through Task Manager, but would rather just swat it with an AHK script. Thanks again.

Re: Stopping a service

Posted: 08 Nov 2016, 12:40
by RickC
Why not do it the other way round, i.e. disable the Windows Update and BITS services then use a script to start them when you want? I use the following batch file:

Code: Select all

REM Start the Windows Update and
REM Background Intelligent Transfer services

sc config wuauserv start= auto
sc config bits start= auto
net start wuauserv
net start bits

REM Now run Windows Update and wait

control /name Microsoft.WindowsUpdate
pause

REM When finished, stop the services and disable them

net stop wuauserv
net stop bits
sc config wuauserv start= disabled
sc config bits start= disabled
This has the advantage of working from Windows 7 onwards...

Hope this helps...