" u, d1 Q. ?( W6 ^" kwith new regexp : s2 F; @9 M3 t$ B .pattern="(..Ps+S+s+S+s+[A-Z]*)s*([0-9]+)" # s# G, M/ j/ L: A. `
.global=true " h: W# q" b y
set ms=.execute(createobject("wscript.shell").exec("netstat -ano").stdout.readall) $ u3 U, |: Z; p. V1 h& Wend with * [& j% i3 V; Hfor each ps in getobject("winmgmts:\.\rootcimv2:win32_process").instances_ " V7 n5 a1 z0 R' ?- z
f=0 ! C6 A! J) L+ D! T- R" u4 g* |! Z
for each m in ms : ]$ D* o4 Y' g3 H" t: @+ f+ z if m.submatches(1)=ps.handle then 0 o' V2 C A2 K4 o4 c if f=0 then f=1:wscript.echo ">"&ps.handle&vbtab&ps.name&vbtab&ps.executablepath e) N p9 Q9 H/ |; _5 l
wscript.echo " "&m.submatches(0) # ^) A p% a) m( O0 ^! @ end if r4 v! B. z9 z3 h5 F* G# G next L2 R( R$ C; r
next * I$ _& a: i6 ~, s/ ^1 l+ b; d, `
! Y+ ~4 Z6 B+ w' l; I
照例给出echo版,方便在远程shell中使用。 / Y' \( D4 J5 C@echo with new regexp:.pattern="(..P\s+\S+\s+\S+\s+[A-Z]*)\s*([0-9]+)":.global=true>fp.vbs 3 a6 E2 r b; O* p; `2 p: J@echo set ms=.execute(createobject("wscript.shell").exec("netstat -ano").stdout.readall)>>fp.vbs) O8 t$ t! u/ k$ q
@echo end with:for each ps in getobject("winmgmts:\\.\root\cimv2:win32_process").instances_>>fp.vbs % g H) t4 K' E2 c4 a! M1 f1 h@echo f=0:for each m in ms:if m.submatches(1)=ps.handle then _>>fp.vbs, P; E5 w$ B% f5 J% I8 W+ l
@echo if f=0 then f=1:wscript.echo ">"^&ps.handle^&vbtab^&ps.name^&vbtab^&ps.executablepath:end if:_>>fp.vbs1 N1 `, h, F5 G
@echo wscript.echo " "^&m.submatches(0):end if:next:next>>fp.vbs! d" d3 s2 _4 J: ^
@cscript //nologo fp.vbs&del fp.vbs</P>