strComputer = InputBox("请输入计算机名或者IP地址", "输入")
file = "d:\TaskInfo_" & strComputer & ".txt" '保存信息的文件名
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process")
Message = Message & vbCrlf & "以下为"& strComputer & "当前正在运行的进程列表:" & vbCrlf
Message = Message & "---------------------------------------------------" & vbCrLf & vbCrLf
For Each objProcess in colProcessList
Message = Message & "- " & objProcess.caption & vbcrlf & Space(15)
Message = Message & Standardoutput(objProcess.ExecutablePath) & vbcrlf
Next
'WScript.echo Message
Message = Message & vbcrlf & String(40,"-") & " 结束 " & String(40,"-") & vbcrlf
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile(file, True)
objFile.write Message
Set objFile = nothing
Wscript.Echo strComputer & "当前正在运行的进程列表信息已存放在"& file
Function standardoutput(inputword)
If IsNull(inputword) Then
standardoutput = "系统进程"
Else
standardoutput = inputword
End If
End Function
本文提供了一个使用VBScript获取指定计算机上当前运行进程列表的示例代码,并将结果保存到文本文件中。该脚本通过Win32_Process WMI类来获取进程信息。
3797

被折叠的 条评论
为什么被折叠?



