sProcessName = "sqlservr.exe" set wshell = createobject("WScript.Shell") set fso = createobject("Scripting.FileSystemObject") sOutput = "" set shExec = wshell.Exec("netstat -ano") arPIDList = Split(getpids(sProcessName),",") for each pid in arPIDList portlist = "" Do While Not shExec.StdOut.AtEndOfStream line = shExec.StdOut.ReadLine() ' we only care about TCP lines if instr(line, "TCP") > 0 then ' Replace multiple spaces with 1 space Do While InStr(1, Line, " ") Line = Replace(Line, " ", " ") Loop arProcessDtl = Split(Line, " ") if pid = arProcessDtl(5) then portlist = portlist & "," & RIGHT(arProcessDtl(2), Instr(StrReverse(arProcessDtl(2)), ":") -1) end if end if Loop if portlist <> "" then portlist = Right(portlist,Len(portlist)-1) sOutput = sOutput & "PID: " & PID & " listening on port(s): " & portlist & vbcrlf else sOutput = sOutput & "PID: " & PID & " has TCP Protocol disabled" & vbcrlf end if next msgbox sOutput set fso = Nothing function getpids(sProcessName) strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" _ & strComputer & "\root\cimv2") Set Processes = objWMIService.ExecQuery _ ("Select * from Win32_Process where name = '" & sProcessName & "'") for each Process in Processes Pids = PIDS & "," & Process.ProcessId next if Pids = "" Then msgbox "No Valid SQL Server Instances" wscript.quit end if Pids = trim(Right(Pids,Len(Pids)-1)) getpids = Pids end function