在vbscript中,如何获取正在运行vb脚本的cmd.exe的进程ID [英] In a vbscript, how can i get the process id of the cmd.exe in which the vb script is running

查看:114
本文介绍了在vbscript中,如何获取正在运行vb脚本的cmd.exe的进程ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在vb脚本中,我想分配一个变量,该变量具有运行vb脚本的cmd.exe的进程ID.有命令吗?

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?

推荐答案

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

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

这篇关于在vbscript中,如何获取正在运行vb脚本的cmd.exe的进程ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆