UI Automation and MMC

RonNYC

Member
Joined
Jan 2, 2013
Messages
8
Programming Experience
10+
Hi. I'm probably making some subtle (or more likely not so subtle) error. I'm trying to drive MMC via a C# program. I can, as a trial, get to the menus of Calc.exe via this code:

C#:
Process calcProcess=Process.Start("c:\\windows\\system32\\calc.exe");
        Thread.Sleep(2000);
 
        AutomationElement aeDesktop = AutomationElement.RootElement;
 
        AutomationElement aeCalc = null;
        int numWaits = 0;
        do
        {
            aeCalc = aeDesktop.FindFirst(TreeScope.Children,
              new PropertyCondition(AutomationElement.NameProperty, "Calculator"));
            Console.WriteLine("Looking for calculator . . . ");
            ++numWaits;
            Thread.Sleep(100);
        } while (aeCalc == null && numWaits < 10);
        if (aeCalc == null)
            throw new Exception("Failed to find calc.EXE");
        else
            Console.WriteLine("Found it!");
        AutomationElementCollection menuCalcBars = aeCalc.FindAll(TreeScope.Children, new PropertyCondition(
        AutomationElement.ControlTypeProperty, ControlType.MenuBar));

And I get a Count of 1 (for the one menu). BUT when I do this with MMC, I get a count of 0, no menu. In UISpy I can see the Calc menu but I can't see the MMC menu. Any help is GREATLY appreciated.
 
Back
Top Bottom