Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding the Running Object Table

Tags:

c#

interop

com

I'm attempting to use the running object table to get a DTE a specific instance of Visual Studio. I was intending to use the technique described on MSDN. I've managed to get one of the instances to list, but not the others.

public static void PrintRot()
{
    IRunningObjectTable rot;
    IEnumMoniker enumMoniker;
    int retVal = GetRunningObjectTable(0, out rot);

    if (retVal == 0)
    {
        rot.EnumRunning(out enumMoniker);

        IntPtr fetched = IntPtr.Zero;
        IMoniker[] moniker = new IMoniker[1];
        while (enumMoniker.Next(1, moniker, fetched) == 0)
        {
            IBindCtx bindCtx;
            CreateBindCtx(0, out bindCtx);
            string displayName;
            moniker[0].GetDisplayName(bindCtx, null, out displayName);
            Console.WriteLine("Display Name: {0}", displayName);
        }
    }
}

[DllImport("ole32.dll")]
private static extern void CreateBindCtx(int reserved, out IBindCtx ppbc);

[DllImport("ole32.dll")]
private static extern int GetRunningObjectTable(int reserved, out IRunningObjectTable prot);

Here are the results:

Display Name: !VisualStudio.DTE.11.0:7120
Display Name: clsid:331F1768-05A9-4DDD-B86E-DAE34DDC998A:
Display Name: !{7751A556-096C-44B5-B60D-4CC78885F0E5}
Display Name: c:\users\dave\documents\visual studio 2012\Projects\MyProj\MyProj.sln
Display Name: !{059618E6-4639-4D1A-A248-1384E368D5C3}

I would expect to see multiple lines with VisualStudio.DTE What am I doing wrong? What should I expect to see?

Edit:

It seems related to whether the app is running elevated privileges. If I'm consistent and use normal mode then it works. However, I'd like it to work regardless, how do I get the ROT for all processes?

like image 807
Dave Hillier Avatar asked Aug 06 '12 20:08

Dave Hillier


1 Answers

are you running another instance elevated? are you running the exe elevated?

When you are a process running as a standard user, you can only see processes/etc that belong to you. So you wouldn't see processes that are running as administrator.

When running with escalated priviliges, you can see all processes belonging to all users.

Ideally, everything would always run as the "least privileged user", see http://en.wikipedia.org/wiki/Principle_of_least_privilege

like image 193
John Gardner Avatar answered Oct 05 '22 19:10

John Gardner