首页 > Windows开发 > 详细

windows process count

时间:2018-11-02 10:05:48      阅读:182      评论:0      收藏:0      [点我收藏+]

In order to get the count of "Word" process, you can refer to the steps as follow.

First, you need to use "System.Runtime.InteropServices", then add .dll "Microsoft.Office.Interop.Word" from "NuGet". The specific operation is as follows:

Click "Manage NuGet Packages..." and type "Microsoft.Office.Interop.Word" in the search bar and download it.

 技术分享图片

技术分享图片

Then, You can use the following code to implement it.

int count = 0;
try
{
    Microsoft.Office.Interop.Word.Application winObj = (Microsoft.Office.Interop.Word.Application)Marshal.GetActiveObject("Word.Application");
    foreach (var item in winObj.Documents) // or winObj.Documents.Count
    {
        count++;
    }
}
catch (System.Runtime.InteropServices.COMException)
{
    count = 0;
}
textBox1.Text = count.ToString();

You can implement how to get count of all processes by using the following code.

Process[] pros = Process.GetProcesses();
int count = 0;
foreach (Process pro in pros)
{
    count++;
}
textBox1.Text = count.ToString();

windows process count

原文:https://www.cnblogs.com/jizhiqiliao/p/9894329.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!