[Solved] Get service name based on process

Get help with using AutoHotkey and its commands and hotkeys
zotune
Posts: 83
Joined: 17 Nov 2014, 17:57

[Solved] Get service name based on process

11 Sep 2015, 05:19

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!
Last edited by tomoe_uehara on 12 Sep 2015, 14:19, edited 1 time in total.
Reason: Marked as solved
User avatar
trismarck
Posts: 506
Joined: 30 Sep 2013, 01:48
Location: Poland

Re: Get service name based on process

11 Sep 2015, 07:26

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
}
But it looks like one process can host multiple services.
zotune
Posts: 83
Joined: 17 Nov 2014, 17:57

Re: Get service name based on process

11 Sep 2015, 08:18

trismarck: Just what I needed, thank you so much!

Return to “Ask For Help”

Who is online

Users browsing this forum: Bodhi, boiler, mikeyww, vanheartnet098, wineguy and 53 guests