1

EDIT: Though tangentially related, the tagged "duplicate" is not a true duplicate of this question, and more importantly does not answer this question (because the problem is different). I am working with a Window Service, not a standalone userspace app.

Here is what I'm working with:

I've written a Windows service (running in Windows Server 2019) in C# that interacts with other software via COM. This other software is not software that I have access to the source for, so I cannot make changes to the COM registration flags or anything like that, but it does register itself and has an API.

I'd like to use the running object table (ROT) from my service to grab an instance of the other software via moniker display name, however the ROT is always empty from the perspective of my service, even after the service itself starts an instance of the other software via Process.Start() which returns a valid PID. To be clear, this runs fine from a standalone Windows console or Windows form application, but not as a service.

The service is configured to log in as a user who is in the administrators group on this machine. Why can't it see anything in the ROT, even after starting a process itself?

Here is a sample code snippet. When run in a console app it counts many monikers, when run in my service, counter is always 0, even after it starts a process.

    [DllImport("ole32.dll")]
    private static extern int CreateBindCtx(uint reserved, out IBindCtx ppbc);
    private static void TestRot()
    {
        IBindCtx context = null;
        IRunningObjectTable rot = null;
        IEnumMoniker monikers = null;
        log.Debug("About to start moniker check");

        CreateBindCtx(0, out context);
        context.GetRunningObjectTable(out rot);
        rot.EnumRunning(out monikers);
        var moniker = new IMoniker[1];

        log.Debug("Beginning moniker loop");
        var counter = 0;

        while (monikers.Next(1, moniker, IntPtr.Zero) == 0)
        {
            counter++;
            var curMoniker = moniker.First();
            string name = null;
            if (curMoniker != null)
            {
                try
                {
                    curMoniker.GetDisplayName(context, null, out name);
                }
                catch (UnauthorizedAccessException)
                {
                    log.Debug($"UnauthorizedAccessException when getting display name for curMoniker");
                }
            }
            log.Debug($"curMoniker: {name}");

        }
        log.Debug("Counted monikers: " + counter);
    }

Thanks in advance.

Luke
  • 743
  • 6
  • 20
  • 3
    Does this answer your question? [Problems accessing the Running Object Table](https://stackoverflow.com/questions/8215203/problems-accessing-the-running-object-table) See link in third answer – xMRi Jan 05 '20 at 18:26
  • @xMRi Thanks for the suggestion. I'm trying to follow along but "Network OLE" doesn't exist anywhere in my registry so it's difficult, and unfortunately it doesn't seem to answer my question. That link contains a lot of information though so I'll continue looking through it, maybe it contains other hints. – Luke Jan 05 '20 at 18:58

0 Answers0