Get to running application from ROT

While cleaning old projects I found this one, that I wrote some time ago, and decided to post here, because it took me long time to figure it out, and although at the end it didn’t work (to clarify things, not because there is something wrong with it, because if how that particular app registered its instances to ROT) I don’t want to go through it again.

IBindCtx bindCtx;

Dictionary<string, Namespace.Application> items = new Dictionary<string, Namespace.Application>();

List<Namespace.Application> itms = new List<Namespace.Application>();

IRunningObjectTable rot;

IEnumMoniker monikerEnum;

IMoniker[] monikers = new IMoniker[1];

IntPtr numFetched;

string description = string.Empty;

object o;

Guid iid = new Guid("some guid here");

Namespace.Application app;

GetRunningObjectTable(0, out  rot);

rot.EnumRunning(out monikerEnum);


while (monikerEnum.Next(1, monikers, IntPtr.Zero)==0)




        rot.GetObject(monikers[0], out o);

        if (o is Namespace.Application)


            CreateBindCtx(0, out bindCtx);

            monikers[0].BindToStorage(bindCtx, null, ref iid, out o);

            //monikers[0].GetDisplayName(bindCtx, null, out description);

            app = o as Namespace.Application;

            //app.ActiveApplication = true;

            //items.Add(description, o as Namespace.Application);

            app.PinOnTop = true;




    catch { }


return items;

Hope it helps someone.

Technorati Tags: , ,