Struggling to figure out how I might restart a windows service with a hotkey. Can you help?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ziwzih
Posts: 15
Joined: 21 May 2017, 18:26

Struggling to figure out how I might restart a windows service with a hotkey. Can you help?

Post by ziwzih » 16 Jan 2022, 17:18

Basically, the wacom drivers seem to need to be restarted more often than I'd like. Thankfully, they put a handy button in the settings to do just that, but I would really love to be able to do this with AHK and not have to click through the settings. Does anyone have any advice on where to find where that service is running, and then restart it with a hotkey?

I have found the "WacomProfessionalService" in services.msc by following this guide. Any advice?

Thank you!!!!!!

User avatar
mikeyww
Posts: 26598
Joined: 09 Sep 2014, 18:38

Re: Struggling to figure out how I might restart a windows service with a hotkey. Can you help?

Post by mikeyww » 16 Jan 2022, 18:00

Code: Select all

F3::Run, sc.exe STOP "WacomProfessionalService",, Hide
Explained: SC

START works, too, in place of STOP.

Code: Select all

svc = WacomProfessionalService
F3::
SoundBeep, 1500
RunWait, sc.exe STOP "%svc%",, Hide
Sleep, 500
RunWait, sc.exe START "%svc%",, Hide
SoundBeep, 1000
Return

ziwzih
Posts: 15
Joined: 21 May 2017, 18:26

Re: Struggling to figure out how I might restart a windows service with a hotkey. Can you help?

Post by ziwzih » 17 Jan 2022, 12:08

Thanks so much for this!! Unfortunately, I can't quite get it to work. I've tried using the display name, service name, and service location listed in the service properties. Any ideas?

User avatar
mikeyww
Posts: 26598
Joined: 09 Sep 2014, 18:38

Re: Struggling to figure out how I might restart a windows service with a hotkey. Can you help?

Post by mikeyww » 17 Jan 2022, 12:16

Use the service name. Try admin mode.

Code: Select all

If !A_IsAdmin && !RegExMatch(DllCall("GetCommandLine", "str"), " /restart(?!\S)") {
 Try Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
 ExitApp
}
svc = WacomProfessionalService

F3::
SoundBeep, 1500
RunWait, sc.exe STOP "%svc%",, Hide
Sleep, 3000
RunWait, sc.exe START "%svc%",, Hide
SoundBeep, 1000
Return

ziwzih
Posts: 15
Joined: 21 May 2017, 18:26

Re: Struggling to figure out how I might restart a windows service with a hotkey. Can you help?

Post by ziwzih » 17 Jan 2022, 12:36

Wow thank you again! Unfortunately, not quite working yet. I did test the code in an admin cmd prompt and "sc stop WTabletServicePro" works flawlessly, but you're right, it definitely needs admin access. I would assume that means that your topline for sending as admin isn't working as expected?

User avatar
mikeyww
Posts: 26598
Joined: 09 Sep 2014, 18:38

Re: Struggling to figure out how I might restart a windows service with a hotkey. Can you help?

Post by mikeyww » 17 Jan 2022, 12:41

It works here for other services, but I do not have the Wacom service. You can test it with a Windows service. The admin code here applies to an uncompiled AHK script.

How are you verifying that the script works or does not work?

ziwzih
Posts: 15
Joined: 21 May 2017, 18:26

Re: Struggling to figure out how I might restart a windows service with a hotkey. Can you help?

Post by ziwzih » 17 Jan 2022, 13:02

Ok I just tested it with a windows service, and it still doesn't seem to be working. I recorded a video of the process if you want to check that out here (ignore the fact that my mouse is misaligned, sorry). But I am testing verifying the script by refreshing the services.msc services app. Additionally, when I stop the wacom service via cmd prompt, my tablet stops working (easiest way to tell whether it's active or not). Thoughts?

Thanks so much again for all your help.

User avatar
mikeyww
Posts: 26598
Joined: 09 Sep 2014, 18:38

Re: Struggling to figure out how I might restart a windows service with a hotkey. Can you help?

Post by mikeyww » 17 Jan 2022, 13:11

You are using a different script. Try the one that I posted first. Run is not RunWait. Documentation explains the difference. If your script does not work, then post the script here.

ziwzih
Posts: 15
Joined: 21 May 2017, 18:26

Re: Struggling to figure out how I might restart a windows service with a hotkey. Can you help?

Post by ziwzih » 17 Jan 2022, 13:26

Sorry for the confusion there! Still, with RunWait, the services dont get stopped with that script. Here's another recording.

I really appreciate you bearing with me on all this!

User avatar
mikeyww
Posts: 26598
Joined: 09 Sep 2014, 18:38

Re: Struggling to figure out how I might restart a windows service with a hotkey. Can you help?

Post by mikeyww » 17 Jan 2022, 13:28

If your script does not work, then post the script here.

ziwzih
Posts: 15
Joined: 21 May 2017, 18:26

Re: Struggling to figure out how I might restart a windows service with a hotkey. Can you help?

Post by ziwzih » 17 Jan 2022, 13:42

Sure thing. Here ya go!

Here it is trying to stop the font cache:

Code: Select all

If !A_IsAdmin && !RegExMatch(DllCall("GetCommandLine", "str"), " /restart(?!\S)") {
 Try Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
 ExitApp
}

svc = FontCache

F3::
SoundBeep, 1500
RunWait, sc.exe STOP "%svc%",, Hide
;Sleep, 3000
;RunWait, sc.exe START "%svc%",, Hide
;SoundBeep, 1000
Return
The wacom service name is WTabletServicePro.

User avatar
mikeyww
Posts: 26598
Joined: 09 Sep 2014, 18:38

Re: Struggling to figure out how I might restart a windows service with a hotkey. Can you help?

Post by mikeyww » 17 Jan 2022, 13:44

I'm not sure that you can stop the font service, but the following one works.

Code: Select all

If !A_IsAdmin && !RegExMatch(DllCall("GetCommandLine", "str"), " /restart(?!\S)") {
 Try Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
 ExitApp
}

svc = stisvc

F3::
SoundBeep, 1500
RunWait, sc.exe STOP "%svc%",, Hide
;Sleep, 3000
;RunWait, sc.exe START "%svc%",, Hide
;SoundBeep, 1000
Return
If you cannot stop your Wacom service with this approach, I do not have an answer. Others here may know more.

ziwzih
Posts: 15
Joined: 21 May 2017, 18:26

Re: Struggling to figure out how I might restart a windows service with a hotkey. Can you help?

Post by ziwzih » 17 Jan 2022, 13:57

Ok well that seems to work well for stopping. Unfortunately it does not work for starting again. And ofc doesn't work for the wacom service. Anyways, thanks again for all your help!! Hopefully others may have an answer.

Post Reply

Return to “Ask for Help (v1)”