within a vb script, I want to assign a variable with the process id of the cmd.exe in which the vb script is running. Is there any command?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Below is the example VB script procedure returning parent process caption and id:
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