本文整理汇总了C#中System.Diagnostics.Process.MachineName属性的典型用法代码示例。如果您正苦于以下问题:C# Process.MachineName属性的具体用法?C# Process.MachineName怎么用?C# Process.MachineName使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Diagnostics.Process
的用法示例。
在下文中一共展示了Process.MachineName属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
using System.Diagnostics;
class GetProcessesByNameClass
{
public static void Main(string[] args)
{
Console.WriteLine("Create notepad processes on remote computer");
Console.Write("Enter remote computer name : ");
string remoteMachineName = Console.ReadLine();
if (remoteMachineName == null)
{
// Prepend a new line to prevent it from being on the same line as the prompt.
Console.WriteLine(Environment.NewLine + "You have to enter a remote computer name.");
return;
}
try
{
// Get all notepad processess into Process array.
Process[] myProcesses = Process.GetProcessesByName("notepad", remoteMachineName);
if (myProcesses.Length == 0)
Console.WriteLine("Could not find notepad processes on remote computer.");
foreach (Process myProcess in myProcesses)
{
Console.WriteLine(
$"Process Name : {myProcess.ProcessName}\n" +
$"Process ID : {myProcess.Id}\n" +
$"MachineName : {myProcess.MachineName}");
}
}
catch (ArgumentException)
{
Console.WriteLine($"The value \'{remoteMachineName}\' is an invalid remote computer name.");
}
catch (InvalidOperationException)
{
Console.WriteLine("Unable to get process information on the remote computer.");
}
catch (PlatformNotSupportedException)
{
Console.WriteLine(
"Finding notepad processes on remote computers " +
"is not supported on this operating system.");
}
}
}