PDA

View Full Version : Finding object in RunningObjectTable in Vista


Fatmumuhomer
04-27-2009, 09:14 PM
Hello, everyone. I come with another question that I hope you guys can offer some insight into! :)

We have an exe that is part of our app. It self-registers the first time is runs. It also registers itself in the RunningObjectTable.

Here is the code for that:

CComPtr<IRunningObjectTable> pRot;
CComPtr<IMoniker> pMk;

sKey = L"VSGMain";
hResult = GetRunningObjectTable(0, &pRot);
hResult = CreateItemMoniker(L"", sKey, &pMk);
hResult = pRot->Register(ROTFLAGS_REGISTRATIONKEEPSALIVE | ROTFLAGS_ALLOWANYCLIENT, GetUnknown(), pMk, &m_dwROT);

//
// Main loop
//
// Currently does nothing (but waits for UI to close)
// (could perform periodic watchdog duties)
//
do
{
#ifdef SEND_DEBUG_OUTPUT
OutputDebugStringA_NL_TS("VSGMAIN: g_hEventUIClosed Check");
#endif

dwMainLoopRetVal = WaitForMultipleObjects(1, &g_hEventUIClosed, FALSE, 30000);

} while (dwMainLoopRetVal == WAIT_TIMEOUT);


//Unregister this object with the Running Object Table so other apps can not reference this instance
hResult = pRot->Revoke(m_dwROT);


Within a C# exe, we then create a hash table of all items in the ROT. We iterate over them until we find the one with the matching Moniker of "VSGMain" and use it.

Under Windows XP, this works fine. The ROT tends to have several items in it, we find the correct one, hold onto a reference to it, and use it to perform tasks within this 2nd exe.

Under Windows Vista, we only see a single item in the ROT. The item is:
clsid:6B7AD2F5-32BF-4B5C-ABEA-FB123102E9AE:!session:2

Obviously something is different between XP and Vista in regards to how objects are made available in the ROT. Any ideas or suggestions?

We've tried viewing the integrity levels using ICACLS.exe. Both of the exe's have a default level of medium. Setting both to high doesn't affect anything. Setting the 1st to low causes it to fail to start up.


Edit/Update:
Ok...with a bit more research, I know that at least one of the problems is that the Register (in the code snippet) is failing. It gives me back this:
-2147467243 - "The class is configured to run as a security id different from the caller"

Not sure what that means, so I am looking into that.

Fatmumuhomer
05-01-2009, 04:04 PM
We figured out the issue.

I figured I'd post it in case anyone finds this while googling in the future.

On Vista, in order for an object to register with the RunningObjectTable, there must be a special registry value.

This is taken from MSDN:

If a COM server wishes to register in the running object table (ROT) and allow any client to access the registration, it must use the ROTFLAGS_ALLOWANYCLIENT flag. An "Activate As Activator" COM server cannot specify ROTFLAGS_ALLOWANYCLIENT because the DCOM service control manager (DCOMSCM) enforces a spoof check against this flag. Therefore, in Windows Vista, COM adds support for a new registry entry that allows the server to stipulate that its ROT registrations be made available to any client:


HKEY_LOCAL_MACHINE\Software\Classes\AppID
{APPID}
ROTFlagsThe only valid value for this REG_DWORD entry is:



ROTREGFLAGS_ALLOWANYCLIENT 0x1The entry must exist in the HKEY_LOCAL_MACHINE hive.

MSDN Link: http://msdn.microsoft.com/en-us/library/ms679687.aspx