获取新创建的流程processID Vbscript

时间:2017-07-10 18:13:12

标签: vbscript process scripting

我正在创建执行calc.exe进程并报告其processID

的代码段
Option Explicit
Dim objWMIService, objProcess, objCalc
Dim strShell, objProgram, strComputer, strExe ,oMethod, svc, sQuery, cproc, iniproc, ProcID

strComputer = "."
strExe = "Calc.exe"
' Connect to WMI
set objWMIService = getobject("winmgmts://"_
& strComputer & "/root/cimv2") 

' Obtain the Win32_Process class of object.
Set objProcess = objWMIService.Get("Win32_Process")
Set objProgram = objProcess.Methods_( _
"Create").InParameters.SpawnInstance_
objProgram.CommandLine = strExe 

'Execute the program now at the command line.
Set strShell = objWMIService.ExecMethod( _
"Win32_Process", "Create", objProgram) 

ProcID = strShell.ProcessId
WScript.echo "The process ID is" &ProcID

我正在验证使用过程资源管理器打开的calc.exe的进程ID,但它与我得到的信息不匹配。

enter image description here ¡任何想法,¿我为什么得到错误的进程ID?

1 个答案:

答案 0 :(得分:2)

获取进程ID的简单方法:

List<String> phoneNumbers = new List<string>();

while (dr.Read())
{
    phoneNumbers.Add(dr["Phone"].ToString());
}
txtsmsphoneno.Text = string.Join(",", phoneNumbers.ToArray());