Getting the .NET Class associated with a process
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
精彩评论