Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# access data from COMAdmin.COMAdminCatalog using WMI

Earlier I was using code as below to grab COM+ applications and verify that my app is running

COMAdmin.COMAdminCatalog catalog = new COMAdmin.COMAdminCatalogClass();
catalog.Connect(servername);
catalog.GetCollection("Applications")

Now I need to perform the same actions but from other domain. So when I try to run the code above I receive authentication error. I have tried to connect via WMI and grab list of COM+ applications from win32 wmi providers, but it seems that it's either not possible or I am doing smth wrong.

I would be pleased if someone could help me to get the list of applications from COMAdminCatalog using credentials.

like image 387
Armedian Avatar asked May 10 '26 22:05

Armedian


1 Answers

You will have to impersonate a different user on the current thread.

using (ImpersonatedUser user = new ImpersonatedUser("USER_NAME", "DOMAIN_NAME", "USER PASSWORD"))
{

    COMAdmin.COMAdminCatalog objCatalog = new COMAdmin.COMAdminCatalog();
    objCatalog.Connect("SERVER_NAME");

    COMAdmin.COMAdminCatalogCollection objAppCollection =
        (COMAdmin.COMAdminCatalogCollection) objCatalog.GetCollection("Applications");

    objAppCollection.Populate();

}

For more details:

  • ImpersonatedUser class: https://blogs.msdn.microsoft.com/joncole/2009/09/21/impersonation-code-in-c/
  • How to impersonate: https://blogs.msdn.microsoft.com/shawnfa/2005/03/21/how-to-impersonate/
like image 84
Fernando Machado Avatar answered May 12 '26 13:05

Fernando Machado



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!