Getting the .NET Class associated with a process

Posted by John P. Grieb on Stack Overflow See other posts from Stack Overflow or by John P. Grieb
Published on 2009-12-25T03:17:17Z Indexed on 2010/04/01 2:03 UTC
Read the original article Hit count: 294

Filed under:
|
|
|

As part of a WMI Coupled provider that I'm creating I need to write an instance enumerator. The code I have is below. What I need to do is get the Class instance associated with the process. Any ideas?

    static public WMIProviderSample GetInstance([ManagementName("ID")] int processId)
    {
        try
        {
            Process[] processes = Process.GetProcessesByName("WMI Provider Sample");
            foreach (Process process in processes)
            {
                if (process.Id == processId)
                {
                    // Need to convert the process to an instance of WMIProviderSampel
                }
            }

            return null;
        }
        catch (ArgumentException)
        {
            return null;
        }
    }

© Stack Overflow or respective owner

Related posts about wmi

Related posts about provider