WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

How To
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Get Process Information from running WinBatch Scripts

 Keywords: Proc Process ID ProcID ProcessID run running script WinBatch current other  

; Computer name and current scripts process id.
strComputer = "."
nProcessId  = DllCall(DirWindows(1):"Kernel32.Dll",long:"GetCurrentProcessId")

objWMIService = ObjectGet("winmgmts:{impersonationLevel=impersonate}!\\":strComputer:"\root\cimv2")

; Get this script's sessionId
strQuery = "select * from win32_process where ProcessId = '":nProcessId:"'"
colProcesses = objWMIService.ExecQuery( strQuery )
ForEach objProcess In colProcesses
    nSessionId = objProcess.SessionId
     Break ;  Should be handled better.
Next

; Get any other WinBatch processes in this session.
strQuery = "select * from win32_process where ProcessId <> '":nProcessId:"'"
strQuery = strQuery:" AND SessionId = '":nSessionId:"'"
strQuery = strQuery:" AND Name = 'WinBatch.exe'"

colProcesses = objWMIService.ExecQuery( strQuery )
ForEach objProcess In colProcesses
    Message("Process ":objProcess.name, "Process Id ":objProcess.ProcessId:" Session ID ":objProcess.SessionId)
Next

objProcess    = 0
colProcesses  = 0
objWMIService = 0

Article ID:   W17929
Filename:   Get Process Information from running WinBatch Scripts.txt
File Created: 2008:10:21:08:28:26
Last Updated: 2008:10:21:08:28:26