标题: [问题求助] 如何获取当前VBS执行的进程号 [打印本页]
作者: watson 时间: 2023-11-2 15:42 标题: 如何获取当前VBS执行的进程号
如何在代码中获取当前VBS代码执行的进程号。
作者: ShowCode 时间: 2023-11-2 16:15
回复 1# watson
1.vbs- Set objShell = CreateObject("WScript.Shell")
- Set objScriptExec = objShell.Exec("tasklist /v /fo csv /fi ""IMAGENAME eq wscript.exe""")
- strScriptPID = objScriptExec.StdOut.ReadAll
- Set objRegEx = CreateObject("VBScript.RegExp")
- objRegEx.Global = True
- objRegEx.Pattern = "(\d+)"
- Set colMatches = objRegEx.Execute(strScriptPID)
- MsgBox strScriptPID
- If colMatches.Count > 0 Then
- MsgBox colMatches(0).SubMatches(0)
- End If
复制代码
作者: ShowCode 时间: 2023-11-2 16:23
回复 1# watson
2.vbs- Set oShell = CreateObject("WScript.Shell")
- Set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
- sCmd = "/k " & Left(CreateObject("Scriptlet.TypeLib").Guid, 38)
- oShell.Run "%comspec% " & sCmd, 0
- Set oChldPrcs = oWMI.ExecQuery("Select * From Win32_Process Where CommandLine Like '%" & sCmd & "'",,32)
- For Each oCols In oChldPrcs
- lOut = oCols.ParentProcessId
- oCols.Terminate
- Exit For
- Next
- MsgBox lOut
复制代码
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |