在vb脚本中,我想分配一个变量,其中包含运行vb脚本的cmd.exe的进程ID。有没有命令?
答案 0 :(得分:2)
以下是返回父进程标题和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