How can I get the path to a Windows service executable WITHOUT using sc qc?

Solution 1:

I encountered this problem too when trying to get the details of a service where the path to the executable was very long. This discussion contains a workaround; you can pass a buffer size as an argument to sc qc. That is, if you do:

sc qc <service name> 5000

the "data area passed to a system call is too small" error goes away.


Also see SC QC MSDN page:

sc [<ServerName>] qc [<ServiceName>] [<BufferSize>]

where:

<BufferSize> Specifies the size (in bytes) of the buffer. The default buffer size is 1,024 bytes.

Solution 2:

I found an workable solution:

reg query "HKLM\System\CurrentControlSet\Services\<serviceName>" /v "ImagePath"

Of course this needs some parsing, but it gives me the full path that the services.msc dialog box provides.


Solution 3:

You can do this in PowerShell with a WMI query like this:

$service = get-wmiobject -query 'select * from win32_service where name="winrm"'; echo $service.pathname

This will give you the full path, including options as they are shown in services.msc. Just replace winrm in my example with whatever service you want to search for.

The above query for winrm should output C:\Windows\System32\svchost.exe -k NetworkService


Solution 4:

Try it using the wmic command line utility. Here's an example of a service on my machine called CrashPlanService.

C:\Users\Ben>wmic service CrashPlanService get PathName

PathName
"C:\Program Files\CrashPlan\CrashPlanService.exe"

Basically, wmic service <<YourService>> get PathName.