Tech Off Post

Single Post Permalink

View Thread: C#:How do you kill an application when all you have is the GUID?
  • User profile image

    You might start with WMI to find the name of the .dll or .exe you want from the component Id, using System.Management, I made a managed class wrapper around Win32_ClassicCOMClassSetting and did this:

    ROOT.CIMV2.ClassicCOMClassSetting.ClassicCOMClassSettingCollection comClasses = ROOT.CIMV2.ClassicCOMClassSetting.GetInstances("ComponentId = \"{0D81DFEC-5610-4A2B-9B57-FC33D21366F0}\"");

    foreach (ROOT.CIMV2.ClassicCOMClassSetting comClass in comClasses)


    Console.WriteLine("AppId= " + comClass.AppID + "\nComponentId= " + comClass.ComponentId + "\nInProcServer= " + comClass.InprocServer + "\nInProcServer32=" + comClass.InprocServer32 + "\nLocalServer=" + comClass.LocalServer + "\nLocalServer32=" + comClass.LocalServer32);



    Which gives me:

    AppId= {0D81DFEC-5610-4A2B-9B57-FC33D21366F0}
    ComponentId= {0D81DFEC-5610-4A2B-9B57-FC33D21366F0}

    Which then can be used to find the process id and kill it. 

    To create the managed class wrapper, if you haven't before, you just navigate in the Server Explorer in Visual Studio, to Servers/Management Classes, right-click, Properties, Add Classes, look under Root/CIMV2 and find and add ClassicCOMClassSetting, then when it's added, right-click on Classic COM Class Settings and select Generate Managed Class, which creates the wrapper for you.

    Warning:  Expanding the Classic COM Class Settings node will take all day to enumerate all the components; it's best to avoid it, and go through DCOM Application Settings or something else that has Classic COM Class Settings as a child for whatever DCOM  apps derive from it.

    One more thing ... note that you may have to drill down through multiple components to find the server hosting your component.