Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8695677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:05:40+00:00 2026-06-13T01:05:40+00:00

I am starting an executable using this code: Process proc = new Process(); proc.StartInfo.FileName

  • 0

I am starting an executable using this code:

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

after this calling proc.Id it gives me some integer, which is not real process ID. In the task manager there is another ID for this process and also I am using MS UI Automation to access this application, which also returns the same ID as in task manager. So my question is how can I get the real process ID of started process?

UPDATE

I found out that on Windows 7 it works fine and returns me the right ID, but not on Windows XP. What can be the reason?

SCENARIO

The scenario of the application is the following. I have a running embedded HTTP server, which is implemented not by me, (here is the source). The client connects to the web server and sends a request to run a program. In the request handler of my server I am just using Process.start() to start the requested application. As a web server the program creates threads for every client session connected to it (I assume so, as I didn’t wrote it). Can this somehow help to identify the problem as it exists only on Windows XP X86 Service Pack 3?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T01:05:40+00:00Added an answer on June 13, 2026 at 1:05 am

    An example of how I did it:

        bool started = false;
        var p = new Process();
    
        p.StartInfo.FileName = "notepad.exe";
    
        started = p.Start();
    
        try {
          var procId = p.Id;
          Console.WriteLine("ID: " + procId);
        }
        catch(InvalidOperationException)
        {
            started = false;
        }
        catch(Exception ex)
        {
            started = false;
        }
    

    Otherwise, try using handles like this:
    Using handlers
    Getting handler

    hWnd = (int) process.MainWindowHandle;
    int processId;
    GetWindowThreadProcessId(hWnd, out processId);
    
    [DllImport("user32")]
    static extern int GetWindowThreadProcessId(IntPtr hWnd, out int processId);
    

    Side note:
    What happens if you get the array of process and iterate over them and compare the PIDs?

    Process[] p = Process.GetProcessesByName( "testprogram" );
    foreach(var proc in p)
        Console.WriteLine("Found: "+proc.Id == myExpectedProcId);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Starting with a recent new version of ADT, I've noticed this new attribute on
I am starting one process from C# code and then i am assign it
Starting a new rails project and we have a well-thought-out color palette, and want
I have a very simple C++ code sample here: char *s = new char[100];
As I write most of my code using MacVIM, I need to add the
In a related question we explored using ProcessBuilder to start external processes in low
Maybe I am not thinking about this correctly. I am starting my second project
i'm applying a digital signature to my executable. Using signtool on Windows XP or
I have an executable that I call using the shell command: Shell (ThisWorkbook.Path &
I need to be able to edit vb.net code using visual studio without stopping

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.