Is there a fast way to get service name based on process?
I have a kill function that I want to use for services too, it says that if a program is running in a certain folder, then kill it, however this won't work for services. And I need to disable them, then re-enable them (when set to run) for them to not run automatically.
Right now I'm using: RunWait, sc config "%Service%" start= disabled,, HIDE
Any help appreciated
Thanks!
[Solved] Get service name based on process
[Solved] Get service name based on process
Last edited by tomoe_uehara on 12 Sep 2015, 14:19, edited 1 time in total.
Reason: Marked as solved
Reason: Marked as solved
Re: Get service name based on process
Code: Select all
Process, Exist, svchost.exe
PID := ErrorLevel
if(names := GetProcessIDServiceNames(PID) )
for idx, name in names
out .= name "`n"
msgbox % out
; sinkfaze: http://ahkscript.org/boards/viewtopic.php?t=77&start=20
GetProcessIDServiceNames(PID)
{
objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\" . A_ComputerName . "\root\cimv2")
WQLQuery := "SELECT * FROM Win32_Service WHERE ProcessId = " PID
names := []
For objService in objWMIService.ExecQuery(WQLQuery)
names.Push(objService.Name)
return names.Length() = 0 ? "" : names
}
Re: Get service name based on process
trismarck: Just what I needed, thank you so much!