获取与进程关联的 .NET 类
作为我正在创建的 WMI Coupled 提供程序的一部分,我需要编写一个实例枚举器。 我的代码如下。我需要做的是获取与进程关联的类实例。有什么想法吗?
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;
}
}
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;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它是我使用 Visual Studio 2008 WinForm 向导创建的 Windows 窗体类。
我正在根据文章 http://msdn.microsoft.com/en-us/library/cc268228.aspx" rel="nofollow noreferrer">http:// /msdn.microsoft.com/en-us/library/cc268228.aspx
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