I need to query a windows service for the path to it's executable via the command prompt. I think the way I would do this is:sc qc myServiceName, but when I do that, I get the following error:

[SC] QueryServiceConfig FAILED 122:

The data area passed to a system call is too small.

[SC] GetServiceConfig needs 1094 bytes

I think this means that the sc command is sending a data structure to some other library that is too small for the data that needs to be returned. Instead of SC nicely retrying with a larger data structure (1094 bytes) it bombs out and gives me this ugly error message. Thanks Micro$oft.

So is there a way to work around this error? I just need the path to the executable, but will parse it out of some other text if needed.

6 Answers 6


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>]


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

  • 2
    FYI, 2^13 = 8192 is the maximum value for the buffer size.
    – nebffa
    Commented Mar 25, 2016 at 6:32
  • sc queryex type= service state= all | find /i "myServiceName lists all services but unfortunately no path.
    – Shayan
    Commented May 18, 2019 at 14:43

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.


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

  • Unfortunately, I can't depend on powershell since XP doesn't have it by default. I need support for XP, server 2008, and 7, all without installing any additional software.
    – Jared
    Commented Nov 23, 2011 at 17:48
  • @Jared that's too bad. You're unable to run this from a single machine against a bunch of remote machines?
    – MDMarra
    Commented Nov 23, 2011 at 18:24
  • No this is actually a bit of script to go in the uninstaller for an application. I figured out a solution that works and added an answer for it though.
    – Jared
    Commented Nov 23, 2011 at 20:01

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

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

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

  • 1
    Doesn't quite work. But, on the other hand, this works: "wmic service | find "<servicename>"
    – djangofan
    Commented Nov 22, 2011 at 23:57
  • @djangofan what output do you get, and with which service? Maybe you've got a different version of wmic (I'm on Windows 7 SP1)? Commented Nov 23, 2011 at 0:34
  • @Ben Pilbrow That didn't work for me either. wmic isn't getting the path name (just returns "PathName" with nothing on the following line). Not sure if this is because there are a lot of parameters embedded in the path making it very long.
    – Jared
    Commented Nov 23, 2011 at 14:53
  • worked for me but i had to process the result a little: ((wmic service SQLBrowser get PathName) -match """)[0].replace(""", "")
    – katbyte
    Commented Nov 23, 2012 at 0:09
  • wmic service works great. Lists all services with their paths.
    – Shayan
    Commented May 18, 2019 at 14:45

Starting from PowerShell 7 :

(Get-Service theServiceName).BinaryPathName
$binpath = (Get-ItemProperty -Path HKLM:SYSTEM\CurrentControlSet\Services\<serviceName>).ImagePath
$binpath = ($binpath).Substring(1,($binpath).IndexOf("<serviceBinFileName>")-1)
  • 1
    If you are already using powershell, why not just use (get-service <servicename>).BinaryPathName? Commented Mar 10, 2020 at 11:51
  • 3
    FWIW, the BinaryPathName property is only available as of PowerShell 7.0. It is not available in PS 5.1.
    – Matt Davis
    Commented Feb 27, 2021 at 6:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .