getting PID of process started by Process.start()

前端 未结 4 997
礼貌的吻别
礼貌的吻别 2020-12-01 08:19

I am starting an executable using this code:

Process proc = new Process();
proc.StartInfo.FileName = executablePath;
proc.Start();
proc.WaitForInputIdle();
<         


        
4条回答
  •  独厮守ぢ
    2020-12-01 08:29

    This:

    using (Process process = Process.Start("notepad.exe"))
    {
        process.WaitForInputIdle();
        Console.WriteLine(process.Id);
    }
    

    Actually works for me:

    http://pasteboard.s3.amazonaws.com/images/1350293463417532.png

    Task Manager:

    http://pasteboard.s3.amazonaws.com/images/1350293536498959.png

    My thoughts:

    Actually your process starts another process and you are trying to get ID of some kind of launcher. (It can start itself by the way).

提交回复
热议问题