DECLARE @sql VARCHAR(4000)= 'wmic service where ProcessId=' + CAST(SERVERPROPERTY('processid') AS NVARCHAR(10)) + ' get startname /format:LIST' CREATE TABLE #output (line VARCHAR(255)) INSERT #output EXEC xp_cmdshell @sql SELECT line FROM #output WHERE line LIKE '%startname=%' DROP TABLE #output