从Silverlight OOB应用程序如何检查进程是否正在运行

时间:2011-10-31 18:06:29

标签: c# silverlight c#-4.0 silverlight-4.0 comautomationfactory

如何通过启用了Silverlight提升信任的浏览器外浏览器来查询您的计算机上是否正在运行某个进程?

1 个答案:

答案 0 :(得分:2)

我认为这可以提供帮助

    private void button1_Click(object sender, RoutedEventArgs e)
    {
        using (dynamic SWbemLocator = AutomationFactory.CreateObject("WbemScripting.SWbemLocator"))
        {
            SWbemLocator.Security_.ImpersonationLevel = 3;
            SWbemLocator.Security_.AuthenticationLevel = 4;
            dynamic IService = SWbemLocator.ConnectServer(".", @"root\cimv2");
            dynamic QueryResults = IService.ExecQuery(@"SELECT * FROM Win32_Process");
            dynamic t = QueryResults.Count;
            for (int i = 0; i < t; i++)
            {
                dynamic p = QueryResults.ItemIndex(i);
                MessageBox.Show(p.name );
            }
        } 
    }