在 vb 脚本中,如何获取 cmd.exe 的进程 ID,其中 vb 脚本是 运行

In a vbscript, how can i get the process id of the cmd.exe in which the vb script is running

在 vb 脚本中,我想用 cmd.exe 的进程 ID 分配一个变量,其中 vb 脚本是 运行。有什么命令吗?

下面是返回 parent 进程标题和 ID 的示例 VB 脚本过程:

GetParentProcessInfo sCaption, sProcessId

MsgBox "Parent Process Caption '" & sCaption & "'" & vbCrLf & "Parent Process Id '" & sProcessId & "'"

Sub GetParentProcessInfo(sCaption, sProcessId)
    With GetObject("winmgmts:\.\root\CIMV2:Win32_Process.Handle='" & CreateObject("WScript.Shell").Exec("rundll32 kernel32,Sleep").ProcessId & "'")
        With GetObject("winmgmts:\.\root\CIMV2:Win32_Process.Handle='" & .ParentProcessId & "'")
            With GetObject("winmgmts:\.\root\CIMV2:Win32_Process.Handle='" & .ParentProcessId & "'")
                sCaption = .Caption
                sProcessId = .ProcessId
            End With
        End With
        .Terminate
    End With
End Sub