Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How to get on Windows PID of the last started process using WScript.Shell or similar?

I know how to start a process and get its PID:

Set oExec = WshShell.Exec( program )
Set pid = oExec.ProcessID

Now the problem is that the program is another batch (or could be VBScript). The batch starts a real program which PID I would like to get.

On Linux (shell script) it is very easy to do. just pid=$!

But what can I do on Windows?

share|improve this question
    
Why not just return the PID as the return value (or just send it to stdout) using VBScript? –  Breakthrough Jul 27 '11 at 10:37
    
Thanks. I think the return value is limited to 256. But it seems like the only way (with reasonable effort) is reading stdout in the VBScript. I think I can use oExec.StdOut property but never tried it so far... –  Dime Jul 28 '11 at 8:11

1 Answer 1

up vote 3 down vote accepted

I think there is no equivalent of $! In Windows.

In case you wish to retrieve the PID of the third process, you can search for it using WMI. A example of this could be found here (just searching and displaying the information) or here (searching and killing the process).

If the executable of the third name is not known, you might want to use a Job object which groups several processes into one object. And you could easily kill all of them at once with TerminateJobObject.

See MSDN for a quick overview or this question on StackOverflow.

However, I don’t know if these methods can be used from VBScript.

share|improve this answer
    
Cannot vote it up :( Not enough reputation. –  Dime Jul 28 '11 at 8:12
    
Do it when you have enough rep - just kidding, not a problem. If the information was helpful, that's enough for me. –  TeX HeX Jul 28 '11 at 8:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.