Early Preview
This is currently very much a preview. Please feel free to try things out,
but don't be upset if anything is not yet working. Feedback is welcome over on our
GitHub Dicussions page.
class System.​Environment
Assembly: System.Runtime
Inheritance: object → Environment
Provides information about, and means to manipulate, the current environment and platform. This class cannot be inherited.
Properties
public static
string
CommandLine
Gets the command line for this process.
public static
ProcessCpuUsage
CpuUsage
<para>Get the CPU usage, including the process time spent running the application code, the process time spent running the operating system code, and the total time spent running both the application and operating system code.</para>
public static
string
CurrentDirectory
Gets or sets the fully qualified path of the current working directory.
public static
int
CurrentManagedThreadId
Gets a unique identifier for the current managed thread.
public static
int
ExitCode
Gets or sets the exit code of the process.
public static
bool
HasShutdownStarted
Gets a value that indicates whether the current application domain is being unloaded or the common language runtime (CLR) is shutting down.
public static
bool
Is64BitOperatingSystem
Gets a value that indicates whether the current operating system is a 64-bit operating system.
public static
bool
Is64BitProcess
Gets a value that indicates whether the current process is a 64-bit process.
public static
bool
IsPrivilegedProcess
Gets a value that indicates whether the current process is authorized to perform security-relevant functions.
public static
string
MachineName
Gets the NetBIOS name of this local computer.
public static
string
NewLine
Gets the newline string defined for this environment.
public static
OperatingSystem
OSVersion
Gets the current platform identifier and version number.
public static
int
ProcessId
Gets the unique identifier for the current process.
public static
int
ProcessorCount
Gets the number of processors available to the current process.
public static
string
ProcessPath
Returns the path of the executable that started the currently executing process. Returns <see langword="null" /> when the path is not available.
public static
string
StackTrace
Gets current stack trace information.
public static
string
SystemDirectory
Gets the fully qualified path of the system directory.
public static
int
SystemPageSize
Gets the number of bytes in the operating system's memory page.
public static
int
TickCount
Gets the number of milliseconds elapsed since the system started.
public static
long
TickCount64
Gets the number of milliseconds elapsed since the system started.
public static
string
UserDomainName
Gets the network domain name associated with the current user.
public static
bool
UserInteractive
Gets a value indicating whether the current process is running in user interactive mode.
public static
string
UserName
Gets the user name of the person who is associated with the current thread.
public static
Version
Version
Gets a version consisting of the major, minor, build, and revision numbers of the common language runtime.
public static
long
WorkingSet
Gets the amount of physical memory mapped to the process context.
Methods
public static
void
Exit​(int exitCode)
Terminates this process and returns an exit code to the operating system.
exitCode
The exit code to return to the operating system. Use 0 (zero) to indicate that the process completed successfully.
public static
string
ExpandEnvironmentVariables​(string name)
Replaces the name of each environment variable embedded in the specified string with the string equivalent of the value of the variable, then returns the resulting string.
Returns A string with each environment variable replaced by its value.
name
A string containing the names of zero or more environment variables. Each environment variable is quoted with the percent sign character (%).
public static
void
FailFast​(string message)
Immediately terminates the process before reporting an error message. For Windows, the error message is written to the Windows Application event log, and the message is included in error reporting to Microsoft. For Unix-like systems, the message, alongside the stack trace, is written to the standard error stream.
message
A message that explains why the process was terminated, or <see langword="null" /> if no explanation is provided.
public static
void
FailFast​(string message,
Exception exception)
Immediately terminates the process before reporting an error message. For Windows, the error message is written to the Windows Application event log, and the message and exception information is included in error reporting to Microsoft. For Unix-like systems, the message alongside the stack trace is written to the standard error stream.
message
A message that explains why the process was terminated, or <see langword="null" /> if no explanation is provided.
exception
An exception that represents the error that caused the termination. This is typically the exception in a <see langword="catch" /> block.
public static
string[]
GetCommandLineArgs​()
Returns a string array containing the command-line arguments for the current process.
Returns An array of strings where each element contains a command-line argument. The first element is the executable file name, and the following zero or more elements contain the remaining command-line arguments.
public static
string
GetEnvironmentVariable​(string variable)
Retrieves the value of an environment variable from the current process.
Returns The value of the environment variable specified by <paramref name="variable" /> , or <see langword="null" /> if the environment variable is not found.
variable
The name of the environment variable.
public static
string
GetEnvironmentVariable​(string variable,
EnvironmentVariableTarget target)
Retrieves the value of an environment variable from the current process or from the Windows operating system registry key for the current user or local machine.
Returns The value of the environment variable specified by the <paramref name="variable" /> and <paramref name="target" /> parameters, or <see langword="null" /> if the environment variable is not found.
variable
The name of an environment variable.
target
One of the <see cref="T:System.EnvironmentVariableTarget" /> values. Only <see cref="F:System.EnvironmentVariableTarget.Process" /> is supported on .NET running on Unix-like systems.
public static
IDictionary
GetEnvironmentVariables​()
Retrieves all environment variable names and their values from the current process.
Returns A dictionary that contains all environment variable names and their values; otherwise, an empty dictionary if no environment variables are found.
public static
IDictionary
GetEnvironmentVariables​(EnvironmentVariableTarget target)
Retrieves all environment variable names and their values from the current process, or from the Windows operating system registry key for the current user or local machine.
Returns A dictionary that contains all environment variable names and their values from the source specified by the <paramref name="target" /> parameter; otherwise, an empty dictionary if no environment variables are found.
target
One of the <see cref="T:System.EnvironmentVariableTarget" /> values. Only <see cref="F:System.EnvironmentVariableTarget.Process" /> is supported on .NET running on Unix-like systems.
public static
string
GetFolderPath​(SpecialFolder folder,
SpecialFolderOption option)
public static
string[]
GetLogicalDrives​()
Retrieves the names of the logical drives on this computer.
Returns An array of strings representing the logical drive names.
public static
void
SetEnvironmentVariable​(string variable,
string value)
Creates, modifies, or deletes an environment variable stored in the current process.
variable
The name of an environment variable.
value
A value to assign to <paramref name="variable" /> .
public static
void
SetEnvironmentVariable​(string variable,
string value,
EnvironmentVariableTarget target)
Creates, modifies, or deletes an environment variable stored in the current process or in the Windows operating system registry key reserved for the current user or local machine.
variable
The name of an environment variable.
value
A value to assign to <paramref name="variable" /> .
target
One of the enumeration values that specifies the location of the environment variable.
public
bool
Equals​(object obj)
Inherited from object
Determines whether the specified object is equal to the current object.
Returns <see langword="true" /> if the specified object is equal to the current object; otherwise, <see langword="false" /> .
obj
The object to compare with the current object.
protected
void
Finalize​()
Inherited from object
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
public
int
GetHashCode​()
Inherited from object
Serves as the default hash function.
Returns A hash code for the current object.
public
Type
GetType​()
Inherited from object
Gets the <see cref="T:System.Type" /> of the current instance.
Returns The exact runtime type of the current instance.
protected
object
MemberwiseClone​()
Inherited from object
Creates a shallow copy of the current <see cref="T:System.Object" /> .
Returns A shallow copy of the current <see cref="T:System.Object" /> .
public
string
ToString​()
Inherited from object
Returns a string that represents the current object.
Returns A string that represents the current object.