Open In App

C# Program to Check Whether a Process is Running in User Interactive Mode or Not Using Environment Class

Last Updated : 01 Nov, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

In C#, Environment Class provides information about the current platform and manipulates, the current platform. It is useful for getting and setting various operating system-related information. We can use it in such a way that it retrieves command-line arguments information, exit codes information, environment variable settings information, contents of the call stack information, and time since the last system boot in milliseconds information. By just using some predefined methods we can get the information of the Operating System using the Environment class. In this article, we will discuss how to check whether the process is running in user interactive mode or not. So we use the UserInteractive property of the Environment class. This property is used to check whether the process is running in user interactive mode or not. It will return true if the process is running in the user interactive mode. Otherwise, return false. 

Syntax:

Environment.UserInteractive

Return Type: The return type of this property is boolean. Returns true if the process is running in user interactive mode or return false if the process is not running in user interactive mode

Example:

C#




// C# program to determine whether a process is
// running in user interactive mode or not
// Using Environment class
using System;
  
class GFG{
  
static public void Main()
{
      
    // Declare a variable
    bool result;
  
    // Checking the process is running in user
    // interactive mode or not
    // Using the UserInteractive property
    result = Environment.UserInteractive;
  
    // Displaying the result
    if (result == true)
        Console.WriteLine("Yes! the process is running " +
                          "in user interactive mode");
    else
        Console.WriteLine("No! the process is not running " +
                          "in user interactive mode");
}
}


Output:

Yes! the process is running in user interactive mode

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads