Stopping a service

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
AHKxx
Posts: 75
Joined: 26 Feb 2014, 01:37

Stopping a service

03 Nov 2016, 16:50

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!
User avatar
Masonjar13
Posts: 1555
Joined: 20 Jul 2014, 10:16
Location: Не Россия
Contact:

Re: Stopping a service

03 Nov 2016, 18:47

Your second bit of code should be used. And are you running as admin?
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build
RickC
Posts: 299
Joined: 27 Oct 2013, 08:32

Re: Stopping a service

05 Nov 2016, 13:11

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
AHKxx
Posts: 75
Joined: 26 Feb 2014, 01:37

Re: Stopping a service

08 Nov 2016, 12:20

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.
RickC
Posts: 299
Joined: 27 Oct 2013, 08:32

Re: Stopping a service

08 Nov 2016, 12:40

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...

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: RandomBoy and 252 guests