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

五迷三道 提交于 2019-12-08 06:38:14

问题


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


来源:https://stackoverflow.com/questions/38765334/in-a-vbscript-how-can-i-get-the-process-id-of-the-cmd-exe-in-which-the-vb-scrip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!