本文整理匯總了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.");
}
}
}