I stumbled across this really useful little script by Bill Wunder the other day when I was attempting to determine which of the 8 SQL instances was hogging all my cpu. Normally I use pslist and process explorer from sysinternals for this type of thing. but this vbscript is simple and just outputs the SQL Server names and their corresponding PIDs.Here is the original posting by Bill with the code http://sigs.sqlpass.org/Resources/Articles/tabid/35/ctl/ArticleView/mid/349/articleId/40/Default.aspxI have reproduced the code below for convenience.Const ForWriting = 2Set objFSO = CreateObject("Scripting.FileSystemObject")'create a file to save the reportSet objLogFile = objFSO.OpenTextFile("c:\SQLserviceList.csv", _ ForWriting, True)'report headingobjLogFile.Write ("pid Service Name")objLogFile.WritelineobjLogFile.Write ("_______ _______________________")objLogFile.Writeline'go after the local serverstrComputer = "."'open the WMI collectionSet objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")'list the process id and name of each SQL Server serviceSet 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 IfNextobjLogFile.Close'open the report in notepadcreateobject("wscript.shell").run "notepad.exe c:\SQLserviceList.csv",1,true
-ec