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 769095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:16:56+00:00 2026-05-14T18:16:56+00:00

For a project I have to start an application in C#, rip out the

  • 0

For a project I have to start an application in C#, rip out the AutomationElement tree related to the process, and then close the application and output the tree. I’m doing this by opening the application using Process.Start. Then I’m finding the AutomationElements related to the spawned process and walking the tree using a combination of TreeWalker and AutomationElement’s FindFirst and FindAll methods.

This runs fine on my computer and runs correctly using NUnit locally. It also runs on the other people in my groups computers. The problem is that it never runs on our central testing server that’s running Hudson. After some hours of debugging, I had a test on Hudson start the application and then print the first level of the AutomationTree. On my computer, this prints all of the windows I have on my desktop. On Hudson, this only prints the Desktop.

Thinking there might be multiple desktops, I tried using TreeWalker’s GetNextSibling function on the RootElement. It still only reported one desktop.

Here’s the code I’m using to start a process.

public bool connect(string[] args)
{
    if (this.process != null) {
        Console.WriteLine("ERROR: Process already connected");
        return false;
    }

    if (!File.Exists(sApplicationPath)) {
        Console.WriteLine(sApplicationPath + " does not exist");
        return false;
    }

    // Turn the command arguments into a single string
    string arguments = "";
    foreach (string arg in args) {
        arguments += arg + " ";
    }

    try {
        // Start the application
        ProcessStartInfo processStartInfo =
            new ProcessStartInfo(sApplicationPath);
        processStartInfo.Arguments = arguments;
        this.process = Process.Start(processStartInfo);

        // Must be a positive integer (non-zero)
        if ( !( iInitialDelay > 0 )  ) {
            Console.WriteLine("Invalid initial delay. " +
                              "Defaulting to 5 seconds.");
            this.iInitialDelay = 5000;
        }

        Thread.Sleep(this.iInitialDelay);
    } catch (Exception ex) {
        Console.WriteLine("WGApplication.connect: " + ex.Message);
        return false;
    }

    // Check if the process still exists
    try {
        /** This part does not return an error, so I think that means the process exists and is started */
        Process check = Process.GetProcessById(process.Id);
    } catch (ArgumentException ex) {
        Console.WriteLine("The process expired before connection was complete");
        Console.WriteLine("Make sure the process is not open anywhere else");
        Console.WriteLine("and that it is able to execute on the host machine.");
        return false;
    }

    // Check if the base automation element exists to verify open
    AutomationElement rootWindow =
        AutomationElement.RootElement.FindChildProcessById(process.Id);
    /** This part returns null, so it can't find the window associated with this process id */

    if (this.process == null) {
        return false;
    } else if (rootWindow == null) {
        // A root window with this process id has not been found
        Console.WriteLine("Cannot find the root window of the created " +
                          "process. Unknown error.");
        return false;
    } else {
        // Everything is good to go
        return true;
    }
}

sApplicationPath is set to the absolute path of the executable. iInitialDelay is a delay to make sure the application has time to start. I’m running this on ‘C:\Windows\System32\notepad.exe’ on Windows Vista SP2 and compiling it with the v3.5 C# compiler.

FindChildProcessById is defined as follows:

public static AutomationElement FindChildProcessById(
    this AutomationElement element, int processId)
{
    var result = element.FindChildByCondition(
        new PropertyCondition(AutomationElement.ProcessIdProperty,
                              processId));

    return result;
}

Remember that this compiles and works on my computer. My test program on Hudson said that the RootElement had no children at all.

So I start the application, confirm it exists, and then I can’t find any windows associated with the process. I can’t find any windows associated with anything except the desktop.

Is this a problem with Hudson? Does Hudson work in some specific way that this code wouldn’t work on it? Is it a problem with my code? The Hudson server is running on a Windows Server 2003 computer. Any help would be appreciated. I know this is a very specific problem which is a reason why I can’t find any solutions online.

  • 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-05-14T18:16:57+00:00Added an answer on May 14, 2026 at 6:16 pm

    Is Hudson running as a service? If so, it may not have the necessary rights to show windows.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ASP.NET MVC project that has a static class in it to
I have a ListView, checkboxes = true, View = List. On the start of
We have an MVC web which is running in Autofac. All the config is
Hi I am evaluating ICUTest for use on a project. My initial view is
Given the following setup, I have three assemblies. Web (ASP.NET MVC 3.0 RC1) Models
I am trying to get the best possible set up for developing my django
I am using the latest release of entity framework 4 - CTP 4 for
I found a realy simple method online that allows me to hide the main
I am using the NetBeans IDE 6.9.1 for working on a JRuby on Rails
When i reset apache and load my website i get the first error below.

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.