Groups | Blog | Home
all groups > dotnet windows forms > august 2004 >

dotnet windows forms : Some more Question Retrieve list of excel app in Running Object Ta


stan_siu
8/6/2004 11:27:02 AM
My question on hand is to retrieve a list of running Excel instances to
attach from a
..NET C# application.

I did some research on the group and learned from Mr Yu[MSFT] of a code
snippet that enumerating the ROT using UCOMIRunningObjectTable interface.

My problem is that when I pass the moniker of value
typeof(Excel.Application).Guid
to the function, it does not find it.
The function only sees the file monikor like "Book1", "book1.xls" instead.

Did I do something wrong ?

Thanks v much.
Stanley Siu

stan_siu
8/6/2004 1:17:01 PM
I found the way of getting correct GUID string:
it is typeof(Excel.ApplicationClass).Guid.ToString()

But this sample return a list of display names of Excel in ROT, how can I
make use of the result to bind it back to the Excel.Application ?

- stanley

public static object[] ActiveObjectList(string moniker)
{
UCOMIRunningObjectTable prot;
UCOMIEnumMoniker pMonkEnum;

ArrayList list = new ArrayList();

int Fetched = 0;

GetRunningObjectTable(0, out prot);
prot.EnumRunning(out pMonkEnum);
pMonkEnum.Reset();
UCOMIMoniker[] pmon = new UCOMIMoniker[1];
while (pMonkEnum.Next(1, pmon, out Fetched) == 0)
{

UCOMIBindCtx pCtx;
CreateBindCtx(0, out pCtx);
string str;
pmon[0].GetDisplayName(pCtx, null, out str);

string tmp = str.ToUpper();
string mon = moniker.ToUpper();

if (tmp.IndexOf(mon) != -1)
list.Add(str);
Marshal.ReleaseComObject(pCtx);
}

return list.ToArray();
}






[quoted text, click to view]
AddThis Social Bookmark Button