Const ForWriting = 2 Set objFSO = CreateObject("Scripting.FileSystemObject") 'create a file to save the report Set objLogFile = objFSO.OpenTextFile("c:\SQLserviceList.csv", _ ForWriting, True) 'report heading objLogFile.Write ("pid Service Name") objLogFile.Writeline objLogFile.Write ("_______ _______________________") objLogFile.Writeline 'go after the local server strComputer = "." 'open the WMI collection Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 'list the process id and name of each SQL Server service Set colListOfServices = objWMIService.ExecQuery _ ("SELECT * FROM Win32_Service") For Each objService in colListOfServices If (InStr(UCase(objService.Name),"MSSQL") = 1) _ OR (InStr(UCase(objService.Name),"SQLAGENT") = 1) Then objLogFile.Write(objService.ProcessID) objLogFile.Write(vbTab) objLogFile.Write(objService.Name) objLogFile.Writeline End If Next objLogFile.Close 'open the report in notepad createobject("wscript.shell").run "notepad.exe c:\SQLserviceList.csv",1,true