简体   繁体   English

了解运行对象表

[英]Understanding the Running Object Table

I'm attempting to use the running object table to get a DTE a specific instance of Visual Studio. 我正在尝试使用运行对象表来获取DTE特定的Visual Studio实例。 I was intending to use the technique described on MSDN . 我打算使用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? 我希望看到VisualStudio.DTE多行。我做错了什么? 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? 但是,无论如何我都希望它可以工作,如何获得所有进程的ROT?

are you running another instance elevated? 你在运行另一个提升的实例吗? are you running the exe elevated? 你在运行exe提升了吗?

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 理想情况下,一切都将作为“最低权限用户”运行,请参阅http://en.wikipedia.org/wiki/Principle_of_least_privilege

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM