Check Service Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
heavyhotuser
Posts: 10
Joined: 05 Dec 2018, 04:06

Check Service

05 Dec 2018, 04:36

I'm trying to detect Service Status via DllCall(). Here is my (not working) code:

Code: Select all

hSCM:=DllCall("Advapi32\OpenSCManagerA", Str, "", Str, "WSearch", UInt, 0xF003F)
hS:=DllCall("Advapi32\OpenServiceA", Ptr, hsCM, Str, "WSearch", UInt, 0)
if DllCall("Advapi32\QuerySerciceStatus", Ptr, hS, UInt, 0x1)
  MsgBox Stoped
else MsgBox Not Stopped
I would like to avoid using Cmd command: sc query "WSearch"
Any help is welcome!
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Check Service

05 Dec 2018, 06:50

Code: Select all

lpServiceName := "WSearch"

if !(hSCManager := DllCall("Advapi32\OpenSCManager", "Ptr", 0, "Ptr", 0, UInt, SC_MANAGER_ALL_ACCESS := 0xF003F))
    throw "OpenSCManager, last error: " A_LastError

if !(hService := DllCall("Advapi32\OpenService", "Ptr", hSCManager, "Str", lpServiceName, UInt, SERVICE_ALL_ACCESS := 0xF01FF))
    throw "OpenService, last error: " A_LastError

VarSetCapacity(_SERVICE_STATUS, 7 * 4, 0)
if !(DllCall("Advapi32\QueryServiceStatus", "Ptr", hService, "Ptr", &_SERVICE_STATUS))
    throw "QueryServiceStatus, last error: " A_LastError

dwCurrentState := NumGet(_SERVICE_STATUS, 4, "UInt")

if (dwCurrentState == (SERVICE_STOPPED := 0x1))
    MsgBox stopped
else
    MsgBox not stopped
this is for unicode btw, change the dllcalls if u need ansi
heavyhotuser
Posts: 10
Joined: 05 Dec 2018, 04:06

Re: Check Service  Topic is solved

05 Dec 2018, 13:17

My deepest respect! You are a real :ugeek:, at least for me! I was miles away from the solution!
Unicode is just fine! I was lost, that's why (hopeless) experiment with Ansi.
It runs very smooth! Thank you very much!!! :D

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: bobstoner289, peter_ahk, Spawnova and 340 guests