2017-05-20 29 views
0

我想查看在我的计算机上运行的所有进程,但cmd命令只给出应用程序,而不是任何脚本或较小的文件。我正在试图找出一种以更高级的方式列出所有进程,以列出当前正在运行的所有进程。有没有人知道用VBScript做这件事的方法?或者如果有更好的方法来做到这一点,它是什么?使用vbscript查看正在运行的进程

+0

请解释一下你是什么意思通过*“不是任何脚本或更小的文件”*。你的意思是文本文件? – GTAVLover

回答

2

使用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.

+1

我会用wmi。不知道任务列表命令。谢谢,我今天学到了一件新事物。 :) – Gurman

0
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 
相关问题