也发一个- strComputer = "."
- Set wmi = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
- Set colPS = wmi.InstancesOf("Win32_Process")
- For Each ps in colPS
- i = (i+1) mod 2
- If i Then
- str= str & FMT(ps.CSName, ps.Name, ps.ProcessId)
- Else
- str= str & " | " & FMT(ps.CSName, ps.Name, ps.ProcessId) & vbCrLf
- End If
- Next
- WScript.Echo str
-
- Function FMT(s1, s2, s3)
- CONST MAX_LEN = 38
- CONST PID_LEN = 5
- Dim s
- s = s1 & " " & s2
- If Len(s) > (MAX_LEN - PID_LEN - 1) then
- 'name与pid之间至少要一个空格,所以再减1
- s = Left(s, MAX_LEN - PID_LEN - 1)
- End If
- s = s & String(MAX_LEN - PID_LEN - Len(s), " ") & s3
- s = s & String(MAX_LEN - Len(s), " ") '后面填充空格
- FMT = s
- End Function
复制代码
|