开发者

Getting the .NET Class associated with a process

开发者 https://www.devze.com 2022-12-14 16:49 出处:网络
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 idea

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");
            fo开发者_运维问答reach (Process process in processes)
            {
                if (process.Id == processId)
                {
                    // Need to convert the process to an instance of WMIProviderSampel
                }
            }

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


It is a Windows Forms Class that I created using the Visual Studio 2008 WinForm Wizard. I'm modifying it to become a WMI Managed class according to the article http://msdn.microsoft.com/en-us/library/cc268228.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消