Just a bit simplified version of @ChirClayton's code:
public string GetServiceInstallPath(string serviceName) => (string) Registry.LocalMachine.OpenSubKey($@"SYSTEM\CurrentControlSet\services\{serviceName}").GetValue("ImagePath");
It doesn't trim possible arguments of service. If they are not required, you can use following:
public string GetServiceInstallPath(string serviceName)
{
var imagePath = (string) Registry.LocalMachine.OpenSubKey($@"SYSTEM\CurrentControlSet\services\{serviceName}").GetValue("ImagePath");
if (string.IsNullOrEmpty(imagePath))
return imagePath;
if (imagePath[0] == '"')
return imagePath.Substring(1, imagePath.IndexOf('"', 1) - 1);
var indexOfParameters = imagePath.IndexOf(' ');
if (indexOfParameters >= 0)
return imagePath.Remove(indexOfParameters);
return imagePath;
}