Reputation: 503
I am creating this snippet that executes a calc.exe process and report its processID
Option Explicit
Dim objWMIService, objProcess, objCalc
Dim strShell, objProgram, strComputer, strExe ,oMethod, svc, sQuery, cproc, iniproc, ProcID
strComputer = "."
strExe = "Calc.exe"
' Connect to WMI
set objWMIService = getobject("winmgmts://"_
& strComputer & "/root/cimv2")
' Obtain the Win32_Process class of object.
Set objProcess = objWMIService.Get("Win32_Process")
Set objProgram = objProcess.Methods_( _
"Create").InParameters.SpawnInstance_
objProgram.CommandLine = strExe
'Execute the program now at the command line.
Set strShell = objWMIService.ExecMethod( _
"Win32_Process", "Create", objProgram)
ProcID = strShell.ProcessId
WScript.echo "The process ID is" &ProcID
I have being validating the process id of the calc.exe opened with proces explorer but it does not match to the info that i am getting.
¡Any ideas about, ¿why I am getting the wrong process id?
Upvotes: 1
Views: 1545
Reputation:
The easy way to get process id:
set process = GetObject("winmgmts:Win32_Process")
process.Create "calc.exe",null,null,processid
wscript.echo " PID : " & Processid
Upvotes: 2