Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
236 views
in Technique[技术] by (71.8m points)

c# - Understanding the Running Object Table

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:usersdavedocumentsvisual studio 2012ProjectsMyProjMyProj.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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...