当前位置: 首页>>代码示例>>C#>>正文


C# Process.GetCurrentProcess方法代码示例

本文整理汇总了C#中System.Diagnostics.Process.GetCurrentProcess方法的典型用法代码示例。如果您正苦于以下问题:C# Process.GetCurrentProcess方法的具体用法?C# Process.GetCurrentProcess怎么用?C# Process.GetCurrentProcess使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Diagnostics.Process的用法示例。


在下文中一共展示了Process.GetCurrentProcess方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BindToRunningProcesses

//引入命名空间
using System;
using System.Diagnostics;
using System.ComponentModel;

namespace MyProcessSample
{
    class MyProcess
    {
        void BindToRunningProcesses()
        {
            // Get the current process.
            Process currentProcess = Process.GetCurrentProcess();

            // Get all processes running on the local computer.
            Process[] localAll = Process.GetProcesses();

            // Get all instances of Notepad running on the local computer.
            // This will return an empty array if notepad isn't running.
            Process[] localByName = Process.GetProcessesByName("notepad");

            // Get a process on the local computer, using the process id.
            // This will throw an exception if there is no such process.
            Process localById = Process.GetProcessById(1234);

            // Get processes running on a remote computer. Note that this
            // and all the following calls will timeout and throw an exception
            // if "myComputer" and 169.0.0.0 do not exist on your local network.

            // Get all processes on a remote computer.
            Process[] remoteAll = Process.GetProcesses("myComputer");

            // Get all instances of Notepad running on the specific computer, using machine name.
            Process[] remoteByName = Process.GetProcessesByName("notepad", "myComputer");

            // Get all instances of Notepad running on the specific computer, using IP address.
            Process[] ipByName = Process.GetProcessesByName("notepad", "169.0.0.0");

            // Get a process on a remote computer, using the process id and machine name.
            Process remoteById = Process.GetProcessById(2345, "myComputer");
        }

        static void Main()
        {
            MyProcess myProcess = new MyProcess();
            myProcess.BindToRunningProcesses();
        }
    }
}
开发者ID:.NET开发者,项目名称:System.Diagnostics,代码行数:49,代码来源:Process.GetCurrentProcess

示例2: Process.GetCurrentProcess()

//引入命名空间
using System;
using System.Diagnostics;
using System.IO;
class TestPathApp {
    static void Main(string[] args) {
        Process p = Process.GetCurrentProcess();
        ProcessModule pm = p.MainModule;
        string s = pm.ModuleName;

        Console.WriteLine(Path.GetFullPath(s));
        Console.WriteLine(Path.GetFileName(s));
        Console.WriteLine(Path.GetFileNameWithoutExtension(s));
        Console.WriteLine(Path.GetDirectoryName(Directory.GetCurrentDirectory()));
        Console.WriteLine(Path.GetPathRoot(Directory.GetCurrentDirectory()));
        Console.WriteLine(Path.GetTempPath());
        Console.WriteLine(Path.GetTempFileName());
    }
}
开发者ID:C#程序员,项目名称:System.Diagnostics,代码行数:19,代码来源:Process.GetCurrentProcess


注:本文中的System.Diagnostics.Process.GetCurrentProcess方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。