【发布时间】:2017-10-20 06:09:53
【问题描述】:
我想查看我的计算机上运行的所有进程,但 cmd 命令只提供应用程序,而不提供任何脚本或较小的文件。我正在尝试找出一种以更高级的方式列出所有进程的方法,该方法将列出当前正在运行的所有内容。有谁知道用 vbscript 做到这一点的方法?或者如果有更好的方法来做到这一点,那是什么?
【问题讨论】:
-
请解释“不是任何脚本或较小的文件”是什么意思。你是说文本文件吗?
我想查看我的计算机上运行的所有进程,但 cmd 命令只提供应用程序,而不提供任何脚本或较小的文件。我正在尝试找出一种以更高级的方式列出所有进程的方法,该方法将列出当前正在运行的所有内容。有谁知道用 vbscript 做到这一点的方法?或者如果有更好的方法来做到这一点,那是什么?
【问题讨论】:
使用TaskList 命令
TaskList 命令可用于显示所有正在运行的应用程序和服务的列表及其详细信息和进程 ID (PID)。
Dim ProTFPath, ProTF, StrPrInfo, StrPrInfoA, PrInfo
Set WshShell = WScript.CreateObject("Wscript.Shell")
Set FSO = WScript.CreateObject("Scripting.FileSystemObject")
ProTFPath = "C:\PROCESSES.txt"
WshShell.Run "CMD /C TASKLIST /V /FO LIST > """ + ProTFPath + """", 0, True
' Here Run is used instead Exec to avoid console window flashes.
If FSO.FileExists(ProTFPath) Then
Set ProTF = FSO.OpenTextFile(ProTFPath, 1, False)
End If
StrPrInfoA = ProTF.ReadAll
PrInfo = Split(StrPrInfoA, VbCrLf + VbCrLf)
For I = 0 To UBound(PrInfo)
WScript.Echo PrInfo(I)
Next
Erase PrInfo
ProTF.Close
如果您不再需要此文件,请在脚本末尾添加以下行:
If FSO.FileExists(ProTFPath) Then
FSO.DeleteFile(ProTFPath, True)
End If
查看更多关于TaskListhere.的信息
【讨论】:
EXE_Process = AllProcessRunningEXE(".")
Vbs_Process = AllProcessRunningVBS (".")
Function AllProcessRunningEXE( strComputerArg )
strProcessArr = ""
Dim Process, strObject
strObject = "winmgmts://" & strComputerArg
For Each Process in GetObject( strObject ).InstancesOf( "win32_process" )
strProcessArr = strProcessArr & ";" & vbNewLine & Process.name
Next
AllProcessRunningEXE = Mid(strProcessArr,3,Len(strProcessArr))
End Function
Function AllProcessRunningVBS (strComputerArg)
strProcessArr = ""
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputerArg & "\root\cimv2")
Set colItems = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = 'cscript.exe' OR Name = 'wscript.exe'")
For Each objItem in colItems
strProcessArr = strProcessArr & ";" & vbNewLine & objItem.CommandLine
Next
AllProcessRunningVBS = Mid(strProcessArr,3,Len(strProcessArr))
Set objWMIService = Nothing
Set colItems = Nothing
End Function
【讨论】: