Windows Service
EXE Path
Service Management
System Administration
Troubleshooting

How to find a Windows service's exe path (PowerShell, sc, registry)

Codemia Knowledge Hub ·

In PowerShell, read the PathName property of Win32_Service. You can also run sc qc <ServiceName> or read the ImagePath registry value. A service stores the command it launches in its configuration, usually an executable path plus optional arguments.

PowerShell: PathName

powershell
Get-CimInstance Win32_Service -Filter "Name='Spooler'" |
    Select-Object Name, State, PathName

Typical output:

text
Name     State   PathName
----     -----   --------
Spooler  Running C:\Windows\System32\spoolsv.exe

For a custom service, PathName may include arguments too, for example "C:\Program Files\MyApp\service.exe" --config C:\MyApp\app.json. The Services UI is not a good source if you need this raw command line.

Command prompt: sc.exe

cmd
sc qc Spooler

Read the BINARY_PATH_NAME line. That is the command line the Service Control Manager uses. This works where PowerShell is restricted or when you are already in a classic command prompt.

sc and the registry both expect the service name, not the display name, so a query by display name fails.

Registry: ImagePath

The configuration lives under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\<ServiceName>, and the ImagePath value holds the executable plus arguments. You can read it without opening Registry Editor:

powershell
Get-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Services\Spooler" |
    Select-Object ImagePath

This is the same stored source the operating system uses, so it helps when higher-level tools are unavailable.

Getting only the .exe from the command line

PathName and ImagePath often include startup arguments, so don't treat the whole value as the executable. Take the first token, respecting quotes; splitting on the first space breaks paths under Program Files.

powershell
1$path = (Get-CimInstance Win32_Service -Filter "Name='Spooler'").PathName
2
3if ($path.StartsWith('"')) {
4    $exe = $path.Split('"')[1]
5} else {
6    $exe = $path.Split(' ')[0]
7}
8
9$exe

This works for many service definitions. For tooling that must handle arbitrary systems, use a proper command-line parser, because spaces and escaped quotes make naive splitting unreliable.

Services that run inside svchost.exe

Some services run in svchost.exe or another shared host process rather than a dedicated binary. The path you see is still correct for how the service process starts, but the actual service logic may be a DLL loaded by that host. So the path tells you what starts the process, not always which module implements the service.


Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design