zoukankan      html  css  js  c++  java
  • Windows Process Count

    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();
  • 相关阅读:
    【贪心+前缀】C. Fountains
    优雅降级和渐进增强
    px和em
    src与href
    css 浮动
    CSS权重及样式优先级问题
    css样式初始化
    品字布局设计
    CSS3新特性
    inline-block的简单理解
  • 原文地址:https://www.cnblogs.com/jizhiqiliao/p/9894329.html
Copyright © 2011-2022 走看看