📌  相关文章
📜  C# 程序检查正在运行的进程是否为 64 位进程或不使用环境类

📅  最后修改于: 2022-05-13 01:55:27.798000             🧑  作者: Mango

C# 程序检查正在运行的进程是否为 64 位进程或不使用环境类

环境类提供有关当前平台的信息并操作当前平台。它对于获取和设置各种与操作系统相关的信息很有用。我们可以使用它来检索命令行参数信息、退出代码信息、环境变量设置信息、调用堆栈信息的内容以及自上次系统启动以来的时间(以毫秒为单位)信息。在本文中,我们可以使用 Environment Class 的Is64BitProcess属性检查系统中正在运行的进程。该方法用于检查当前进程是否为 64 位进程。如果当前进程是 64 位进程,则返回 true,否则返回 false。

句法:

返回类型:此属性的返回类型是布尔值。如果进程是 64 位进程,它将返回 true。否则,返回假。

示例 1:

在这个例子中,我们在 64 位机器上运行我们的代码。

C#
// C# program to determine whether the given 
// process is 64-bit process or not. Using 
// Is64BitProcess process of Environment Class
using System;
  
class GFG{
      
static public void Main()
{
      
    // Declare a boolean variable and set to false
    bool process = false;
      
    // Set the method to the initialized variable
    process = Environment.Is64BitProcess;
      
    // Check whether the current process 
    // is 64-bit process or not
    if (process == true)
        Console.WriteLine("The current process is 64-bit process");
    else
        Console.WriteLine("The current process is not 64-bit process");
}
}


C#
// C# program to determine whether the given 
// process is 64-bit process or not. Using 
// Is64BitProcess process of Environment Class
using System;
  
class GFG{
      
static public void Main()
{
      
    // Declare a boolean variable and set to false
    bool process = false;
      
    // Set the method to the initialized variable
    process = Environment.Is64BitProcess;
      
    // Check whether the current process 
    // is 64-bit process or not
    if (process == true)
        Console.WriteLine("The current process is 64-bit process");
    else
        Console.WriteLine("The current process is not 64-bit process");
}
}


输出:

The current process is 64-bit process

示例 2:

在这个例子中,我们在 32 位机器上运行相同的代码,我们得到不同的输出,因为现在进程是 32 位的。

C#

// C# program to determine whether the given 
// process is 64-bit process or not. Using 
// Is64BitProcess process of Environment Class
using System;
  
class GFG{
      
static public void Main()
{
      
    // Declare a boolean variable and set to false
    bool process = false;
      
    // Set the method to the initialized variable
    process = Environment.Is64BitProcess;
      
    // Check whether the current process 
    // is 64-bit process or not
    if (process == true)
        Console.WriteLine("The current process is 64-bit process");
    else
        Console.WriteLine("The current process is not 64-bit process");
}
}

输出:

The current process is not 64-bit process