Boris Raznikov
Boris Raznikov

Reputation: 2443

Win32 determine process ID

I want to create a process in Win32 .NET can I determine FOR the OS which PID the application will get ?

Update:

1) I am asking it because I have a problem in which I have 2 .NET application (the same ones) that I have each one of them got parameter ID and I want using a script (using the parameter) to decide which is the one and get it's PID 2) I want to know it from out side not from the .NET Process. I need for a script

Upvotes: 1

Views: 635

Answers (1)

JaredPar
JaredPar

Reputation: 754525

You can never determine what PID a process will get. You can only determine what PID a process did get after you start the process.

In .Net you can do the following

var newProcess = Process.Start(someExeFile);
var id = newProcess.Id

In Win32 the CreateProcess function will return an PROCESS_INFORMATION struct as an out parameter of the function. It has the new PID as one of it's members (dwProcessId)

Upvotes: 6

Related Questions