So, I wrote this little batch (called GetPids.bat) and added it to the quicklaunch.
Code: Select all
@echo off
setlocal enabledelayedexpansion
:: get rid of MpCmdRun.exe while we're at it
:start
taskkill /f /t /im mpcmdrun.exe
cls
ping 1.1.1.1 -n 1 -w 0.5 >nul
cls
:: display pids with net connection
netstat -o -n >pid.txt
type pid.txt
echo.
echo Process Name PID Session Name Session# Mem Usage Count
echo Please Wait...
for /f "skip=4 tokens=5*" %%i in (pid.txt) do tasklist /nh /fi "pid eq %%i" >>out.txt
cursorpos 0 -1
:: display process names removing duplicates
if not exist out.txt goto :prompt
echo. >index.dat
for /f "tokens=*" %%i in (out.txt) do if "%%i" neq "!pid!" (
set pid=%%i
find "%%i" index.dat >nul
if errorlevel 1 (
find /c "%%i" out.txt >out2.txt
for /f "tokens=3" %%i in (out2.txt) do set count=%%i
echo !pid! [!count!] >> index.dat
set /a total=!total!+!count! ) )
type index.dat
echo Total [!total!]
:: clean up and repeat?
:prompt
echo.
set pid=
set count=
set total=
del /q pid.txt out.txt out2.txt index.dat
set /p temp="<- Return = Refresh ->"
goto :start
Yes I know my formatting is awful. It's my style. I hate lines that only have a ) or a (. They seem redundant to me.
The reason I clean up the environment variables at the end is cause if that doesn't happen the output gets messed up. If it wasn't looping the "set var=" lines could be removed as I noticed XP doesn't keep environment variables from one session of cmd to another.
The hardest bit was getting the "Please Wait..." line to be overwritten. Spent the whole day reading up and trying various solutions. None of them worked so I compromised by using Aacini's CursorPos.exe auxiliary program. So it's not pure XP cmd DOS but then it's emulated so not pure DOS anyway.
Let me know whatcha think of it