Getting a pid of a process created in C#
Posted
by Adrian
on Stack Overflow
See other posts from Stack Overflow
or by Adrian
Published on 2010-03-29T17:27:21Z
Indexed on
2010/03/29
17:33 UTC
Read the original article
Hit count: 253
Lets say that I'm trying to create a new process with the following code:
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
p.StartInfo.FileName = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "\\AwesomeFile.exe";
p.StartInfo.Arguments = "parameter1 parameter2";
p.StartInfo.CreateNoWindow = true;
p.Start();
and right in the next line, I'll try to get a pid of that process with the following line:
MessageBox.Show(p.Id);
This line is giving me the "No process is associated with this object." error. Any idea as to why this error occurs?
© Stack Overflow or respective owner