# dotnet/dotnet-api-docs

Switch branches/tags
Nothing to show
Fetching contributors…
Cannot retrieve contributors at this time
2310 lines (2002 sloc) 150 KB
 System.Runtime.Extensions 4.0.0.0 4.0.10.0 4.1.0.0 4.2.0.0 4.2.1.0 mscorlib 1.0.5000.0 2.0.0.0 2.0.5.0 4.0.0.0 netstandard 2.0.0.0 System.Object System.Runtime.InteropServices.ComVisible(true) Provides information about, and means to manipulate, the current environment and platform. This class cannot be inherited. class to retrieve information such as command-line arguments, the exit code, environment variable settings, contents of the call stack, time since last system boot, and the version of the common language runtime. ## Examples The following example demonstrates displays a list of information about the current environment. [!code-cpp[environment.class#1](~/samples/snippets/cpp/VS_Snippets_CLR/environment.class/CPP/env0.cpp#1)] [!code-csharp[environment.class#1](~/samples/snippets/csharp/VS_Snippets_CLR/environment.class/CS/env0.cs#1)] [!code-vb[environment.class#1](~/samples/snippets/visualbasic/VS_Snippets_CLR/environment.class/VB/env0.vb#1)] ]]> Property mscorlib 1.0.5000.0 2.0.0.0 2.0.5.0 4.0.0.0 netstandard 2.0.0.0 System.Runtime.Extensions 4.2.0.0 4.2.1.0 get: System.Security.SecuritySafeCritical System.String Gets the command line for this process. A string containing command-line arguments. method to retrieve the command-line information parsed and stored in an array of strings. The maximum size of the command-line buffer is not set to a specific number of characters; it varies depending on the Windows operating system that is running on the computer. ## Examples The following example displays its own command line. [!code-cpp[environment.commandline#1](~/samples/snippets/cpp/VS_Snippets_CLR/environment.CommandLine/CPP/commandline.cpp#1)] [!code-csharp[environment.commandline#1](~/samples/snippets/csharp/VS_Snippets_CLR/environment.CommandLine/CS/commandline.cs#1)] [!code-vb[environment.commandline#1](~/samples/snippets/visualbasic/VS_Snippets_CLR/environment.CommandLine/VB/commandline.vb#1)] ]]> for read access to the PATH environment variable. Associated enumeration: Property mscorlib 1.0.5000.0 2.0.0.0 2.0.5.0 4.0.0.0 netstandard 2.0.0.0 System.Runtime.Extensions 4.2.0.0 4.2.1.0 System.String Gets or sets the fully qualified path of the current working directory. A string containing a directory path. property. [!code-cpp[System.Environment#4](~/samples/snippets/cpp/VS_Snippets_CLR_System/system.Environment/CPP/Vars1.cpp#4)] [!code-csharp[System.Environment#4](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Environment/CS/Vars1.cs#4)] [!code-vb[System.Environment#4](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Environment/VB/Vars1.vb#4)] ]]> Attempted to set to an empty string (""). Attempted to set to An I/O error occurred. Attempted to set a local path that cannot be found. The caller does not have the appropriate permission. for writing to files or directories in a set operation. Associated enumeration: for access to the information in the path itself in a get operation. Associated enumeration: Property System.Runtime.Extensions 4.0.0.0 4.0.10.0 4.1.0.0 4.2.0.0 4.2.1.0 mscorlib 2.0.5.0 4.0.0.0 netstandard 2.0.0.0 get: System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.Success) get: System.Runtime.TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries") System.Int32 Gets a unique identifier for the current managed thread. An integer that represents a unique identifier for this managed thread. To be added. Method System.Runtime.Extensions 4.1.0.0 4.2.0.0 4.2.1.0 mscorlib 1.0.5000.0 2.0.0.0 2.0.5.0 4.0.0.0 netstandard 2.0.0.0 System.Security.SecuritySafeCritical System.Void The exit code to return to the operating system. Use 0 (zero) to indicate that the process completed successfully. Terminates this process and returns an exit code to the operating system. method differs from using your programming language's return statement in the following ways: - always terminates an application. Using the return statement may terminate an application only if it is used in the application entry point, such as in the Main method. - terminates an application immediately, even if other threads are running. If the return statement is called in the application entry point, it causes an application to terminate only after all foreground threads have terminated. - requires the caller to have permission to call unmanaged code. The return statement does not. - If is called from a try or catch block, the code in any finally block does not execute. If the return statement is used, the code in the finally block does execute. - If is called when code in a [constrained execution region](~/docs/framework/performance/constrained-execution-regions.md) (CER) is running, the CER will not complete execution. If the return statement is used, the CER completes execution. ]]> The caller does not have sufficient security permission to perform this function. for the ability to call unmanaged code. Associated enumeration: Property mscorlib 1.0.5000.0 2.0.0.0 2.0.5.0 4.0.0.0 netstandard 2.0.0.0 System.Runtime.Extensions 4.2.0.0 4.2.1.0 get: System.Security.SecuritySafeCritical set: System.Security.SecuritySafeCritical System.Int32 Gets or sets the exit code of the process. A 32-bit signed integer containing the exit code. The default value is 0 (zero), which indicates that the process completed successfully. [!WARNING] > The property is a signed 32-bit integer. To prevent the property from returning a negative exit code, you should not use values greater than or equal to 0x80000000. Use a non-zero number to indicate an error. In your application, you can define your own error codes in an enumeration, and return the appropriate error code based on the scenario. For example, return a value of 1 to indicate that the required file is not present and a value of 2 to indicate that the file is in the wrong format. For a list of exit codes used by the Windows operating system, see [System Error Codes](http://msdn.microsoft.com/library/ms681381$$v=vs.85$$) in the Windows documentation. ## Examples The following is a simple app named Double.exe that doubles an integer value passed to it as a command-line argument. The value assigns error codes to the property to indicate error conditions. Note that you must add a reference to the System.Numerics.dll assembly to successfully compile the example. [!code-csharp[System.Environment.ExitCode#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.environment.exitcode/cs/double.cs#1)] [!code-vb[System.Environment.ExitCode#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.environment.exitcode/vb/double.vb#1)] The example can then be invoked from a batch file such as the following, which makes its error codes accessible by using the ERRORLEVEL command.  echo off Double.exe %1 If errorlevel 1639 goto NoArg if errorlevel 534 goto Overflow if errorlevel 160 goto BadArg if errorlevel 0 echo Completed Successfully goto :EOF :NoArg echo Missing argument goto :EOF : Overflow echo Arithmetic overflow goto :EOF :BadArg echo Invalid argument goto :EOF  The following shows some sample output produced by invoking the batch file. Output >getdouble 123>echo offResult: 246Completed Successfully>getdouble 5912323109093>echo offArithmetic overflow>getdouble>echo offMissing argument>getdouble "a string">echo offInvalid argument  Note that code for Double.exe is identical in function to the following example, except that the former defines an entry point named Main that has no return value, whereas this example defines an entry point named Main that returns an integer. [!code-csharp[System.Environment.ExitCode#2](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.environment.exitcode/cs/double1.cs#2)] [!code-vb[System.Environment.ExitCode#2](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.environment.exitcode/vb/double1.vb#2)] ]]> Method System.Runtime.Extensions 4.0.10.0 4.1.0.0 4.2.0.0 4.2.1.0 mscorlib 1.0.5000.0 2.0.0.0 2.0.5.0 4.0.0.0 netstandard 2.0.0.0 System.Security.SecuritySafeCritical System.String A string containing the names of zero or more environment variables. Each environment variable is quoted with the percent sign character (%). 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. A string with each environment variable replaced by its value. method. Replacement only occurs for environment variables that are set. For example, suppose name is "MyENV = %MyENV%". If the environment variable, MyENV, is set to 42, this method returns "MyENV = 42". If MyENV is not set, no change occurs; this method returns "MyENV = %MyENV%". The size of the return value is limited to 32K. ## Examples The following example shows how to obtain the system drive and system root variables. [!code-cpp[Environment.ExpandEnvironmentVariables#1](~/samples/snippets/cpp/VS_Snippets_CLR/environment.ExpandEnvironmentVariables/CPP/expandenvironmentvariables.cpp#1)] [!code-csharp[Environment.ExpandEnvironmentVariables#1](~/samples/snippets/csharp/VS_Snippets_CLR/environment.ExpandEnvironmentVariables/CS/expandenvironmentvariables.cs#1)] [!code-vb[Environment.ExpandEnvironmentVariables#1](~/samples/snippets/visualbasic/VS_Snippets_CLR/environment.ExpandEnvironmentVariables/VB/expandenvironmentvariables.vb#1)] ]]> is . for the ability to access the environment variables in . Associated enumeration: System.Runtime.Extensions 4.0.0.0 4.0.10.0 4.1.0.0 4.2.0.0 Immediately terminates a process after writing a message to the Windows Application event log, and then includes the message and optional exception information in error reporting to Microsoft. Method System.Runtime.Extensions 4.0.0.0 4.0.10.0 4.1.0.0 4.2.0.0 4.2.1.0 mscorlib 2.0.0.0 2.0.5.0 4.0.0.0 netstandard 2.0.0.0 System.Security.SecurityCritical System.Void A message that explains why the process was terminated, or if no explanation is provided. Immediately terminates a process after writing a message to the Windows Application event log, and then includes the message in error reporting to Microsoft. method writes the message string to the Windows Application event log, creates a dump of your application, and then terminates the current process. The message string is also included in error reporting to Microsoft. Use the method instead of the method to terminate your application if the state of your application is damaged beyond repair, and executing your application's try/finally blocks and finalizers will corrupt program resources. Information is reported to Microsoft by using Windows Error Reporting. For more information, see [Windows Error Reporting: Getting Started](http://msdn.microsoft.com/library/windows/hardware/dn641144.aspx). ## Examples The following example writes a log entry to the Windows Application event log and terminates the current process. [!code-csharp[environment.FailFast#1](~/samples/snippets/csharp/VS_Snippets_CLR/environment.FailFast/cs/ff.cs#1)] [!code-vb[environment.FailFast#1](~/samples/snippets/visualbasic/VS_Snippets_CLR/environment.FailFast/vb/ff.vb#1)] ]]> requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code. Method System.Runtime.Extensions 4.0.0.0 4.0.10.0 4.1.0.0 4.2.0.0 4.2.1.0 mscorlib 2.0.5.0 4.0.0.0 netstandard 2.0.0.0 System.Security.SecurityCritical System.Void A message that explains why the process was terminated, or if no explanation is provided. An exception that represents the error that caused the termination. This is typically the exception in a block. Immediately terminates a process after writing a message to the Windows Application event log, and then includes the message and exception information in error reporting to Microsoft. method writes the message string to the Windows Application event log, creates a dump of your application, and then terminates the current process. Information is reported to Microsoft by using Windows Error Reporting. For more information, see [Windows Error Reporting: Getting Started](http://msdn.microsoft.com/library/windows/hardware/dn641144.aspx). Error reporting to Microsoft includes message and exception information, which provides details used to classify the error. Although exception is not handled because the process is terminated, the contextual information that raised the exception is still obtained. If exception is null, or if exception is not thrown, this method operates the same as the method overload. Use the method instead of the method to terminate your application if the state of your application is damaged beyond repair, and executing your application's try/finally blocks and finalizers will corrupt program resources. ]]> requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code. Method System.Runtime.Extensions 4.1.0.0 4.2.0.0 4.2.1.0 mscorlib 1.0.5000.0 2.0.0.0 2.0.5.0 4.0.0.0 netstandard 2.0.0.0 System.Security.SecuritySafeCritical System.String[] Returns a string array containing the command-line arguments for the current process. An array of string 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. . The remaining elements contain any additional tokens entered on the command line. The program file name can, but is not required to, include path information. Command line arguments are delimited by spaces. You can use double quotation marks (") to include spaces within an argument. The single quotation mark ('), however, does not provide this functionality. If a double quotation mark follows two or an even number of backslashes, each proceeding backslash pair is replaced with one backslash and the double quotation mark is removed. If a double quotation mark follows an odd number of backslashes, including just one, each preceding pair is replaced with one backslash and the remaining backslash is removed; however, in this case the double quotation mark is not removed. The following table shows how command line arguments can be delimited, and assumes MyApp as the current executing application. |Input at the command line|Resulting command line arguments| |-------------------------------|--------------------------------------| |MyApp alpha beta|MyApp, alpha, beta| |MyApp "alpha with spaces" "beta with spaces"|MyApp, alpha with spaces, beta with spaces| |MyApp 'alpha with spaces' beta|MyApp, 'alpha, with, spaces', beta| |MyApp \\\alpha \\\\"beta|MyApp, \\\alpha, \\beta| |MyApp \\\\\"alpha \"beta|MyApp, \\"alpha, "beta| To obtain the command line as a single string, use the property. ## Examples The following example displays the application's command line arguments. [!code-cpp[Environment.GetCommandLineArgs#1](~/samples/snippets/cpp/VS_Snippets_CLR/Environment.GetCommandLineArgs/CPP/getcommandlineargs.cpp#1)] [!code-csharp[Environment.GetCommandLineArgs#1](~/samples/snippets/csharp/VS_Snippets_CLR/Environment.GetCommandLineArgs/CS/getcommandlineargs.cs#1)] [!code-vb[Environment.GetCommandLineArgs#1](~/samples/snippets/visualbasic/VS_Snippets_CLR/Environment.GetCommandLineArgs/VB/getcommandlineargs.vb#1)] ]]> The system does not support command-line arguments. for read access to the PATH environment variable. Associated enumeration: System.Runtime.Extensions 4.0.10.0 4.1.0.0 4.2.0.0 Retrieves the value of an environment variable. Method System.Runtime.Extensions 4.0.10.0 4.1.0.0 4.2.0.0 4.2.1.0 mscorlib 1.0.5000.0 2.0.0.0 2.0.5.0 4.0.0.0 netstandard 2.0.0.0 System.Security.SecuritySafeCritical System.String The name of the environment variable. Retrieves the value of an environment variable from the current process. The value of the environment variable specified by , or if the environment variable is not found. method retrieves an environment variable from the environment block of the current process only. It is equivalent to calling the method with a target value of . To retrieve all environment variables along with their values, call the method. Environment variable names are case-sensitive on Linux and macOS but are not case-sensitive on Windows. ### On Windows systems On Windows systems, the environment block of the current process includes: - All environment variables that are provided to it by the parent process that created it. For example, a .NET application launched from a console window inherits all of the console window's environment variables. If there is no parent process, per-machine and per-user environment variables are used instead. For example, a new console window has all per-machine and per-user environment variables defined at the time it was launched. - Any variables added to the process block while the process is running by calling either the method or the method with a target value of . These environment variables persist until the .NET application terminates. If environment variables are created after the process has started, you can use this method to retrieve only those variables that were created by calling the method or the method with a target value of .. ### On macOS and Linux systems On macOS and Linux, the environment block of the current proccess includes the following environment variables: - All environment variables that are provided to it by the parent process that created it. For .NET applications launched from a shell, this includes all environment variables defined in the shell. - Any variables added to the process block while the process is running by calling either the method or the method with a target value of . These environment variables persist until the .NET application terminates. .NET Core on macOS and Linux does not support per-machine or per-user environment variables. ## Examples The following example uses the method to retrieve the windir environment variable, which contains the path of the Windows directory. [!code-cpp[System.Environment#4](~/samples/snippets/cpp/VS_Snippets_CLR_System/system.Environment/CPP/Vars1.cpp#4)] [!code-csharp[System.Environment#4](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Environment/CS/Vars1.cs#4)] [!code-vb[System.Environment#4](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Environment/VB/Vars1.vb#4)] The following example attempts to retrieve the value of an environment variable named Test1 from the process environment block. If the variable doesn't exist, the example creates its and retrieves its value. The example displays the value of the variable. If the example created the variable, it also calls the method with each member of the enumeration to establish that the variable can be retrieved only from the current process environment block. Finally, if the example created the variable, it deletes it. [!code-csharp[System.Environment.GetEnvironmentVariable#2](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.environment.getenvironmentvariable/cs/getenvironmentvariableex1.cs#2)] [!code-vb[System.Environment.GetEnvironmentVariable#2](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.environment.getenvironmentvariable/vb/getenvironmentvariableex1.vb#2)] ]]> is . The caller does not have the required permission to perform this operation. for the ability to read the value of . Associated enumeration: Method mscorlib 2.0.0.0 2.0.5.0 4.0.0.0 netstandard 2.0.0.0 System.Runtime.Extensions 4.2.0.0 4.2.1.0 System.Security.SecuritySafeCritical System.String The name of an environment variable. One of the values. 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. The value of the environment variable specified by the and parameters, or if the environment variable is not found. method. Environment variable names are case-sensitive on Linux and macOS but are not case-sensitive on Windows. ### On Windows systems On Windows, the target parameter specifies whether the environment variable is retrieved from the current process or from the Windows operating system registry key for the current user or local machine. All per-user and per-machine environment variables are automatically copied into the environment block of the current process, as are any other environment variables that are available to the parent process that created the .NET process. However, environment variables added only to the environment block of the current process by calling either the method or the method with a target value of persist only for the duration of the process. ### On macOS and Linux systems On macOS and Linux, the GetEnvironmentVariable(String, EnvironmentVariableTarget) method supports a target value of only. Calls with a target value of or are not supported and return null. Per-process environment variables are: - Those inherited from the parent process, typically the shell used to invoke dotnet.exe or to launch the .NET application. - Those defined by calling either the method or the method with a target value of . These environment variables persist only until the dotnet process or the .NET application terminates. ## Examples The following example creates environment variables for the Process, User, and Machine targets, checks whether the operating system registry contains the User and Machine environment variables, then deletes the environment variables. [!code-cpp[environment.getsetenvar#1](~/samples/snippets/cpp/VS_Snippets_CLR/environment.getsetenvar/CPP/source.cpp#1)] [!code-csharp[environment.getsetenvar#1](~/samples/snippets/csharp/VS_Snippets_CLR/environment.getsetenvar/CS/gsev.cs#1)] [!code-vb[environment.getsetenvar#1](~/samples/snippets/visualbasic/VS_Snippets_CLR/environment.getsetenvar/VB/gsev.vb#1)] ]]> is . is not a valid value. The caller does not have the required permission to perform this operation. for the ability to read the value of if is (Associated enumeration: ), or for full access to environment variables if is or (Associated enumeration: ). System.Runtime.Extensions 4.0.10.0 4.1.0.0 4.2.0.0 Retrieves all environment variable names and their values. Method System.Runtime.Extensions 4.0.10.0 4.1.0.0 4.2.0.0 4.2.1.0 mscorlib 1.0.5000.0 2.0.0.0 2.0.5.0 4.0.0.0 netstandard 2.0.0.0 System.Security.SecuritySafeCritical System.Collections.IDictionary Retrieves all environment variable names and their values from the current process. A dictionary that contains all environment variable names and their values; otherwise, an empty dictionary if no environment variables are found. . ### On Windows systems On Windows systems, the GetEnvironmentVariables method returns the following environment variabless: - All per-machine environment variables that are defined at the time the process is created, along with their values. - All per-user environment variables that are defined at the time the process is created, along with their values. - Any variables inherited from the parent process from which the .NET application was launched or added to the process block while the process is running. Environment variables are added while the process is running by calling either the method or the method with a target value of . ### On macOS and Linux systems On MacOS and Linux, the GetEnvironmentVariables method retrieves the name and value of all environment variables that are inherited from the parent process that launched the dotnet process or that are defined within the scope of the dotnet process itself. Once the dotnet process ends, these latter environment variables cease to exist. .NET Core does not support per-machine or per-user environment variables. ## Examples The following example demonstrates the method. [!code-cpp[Environment.GetEnvironmentVariables#1](~/samples/snippets/cpp/VS_Snippets_CLR/Environment.GetEnvironmentVariables/CPP/getenvironmentvariables.cpp#1)] [!code-csharp[Environment.GetEnvironmentVariables#1](~/samples/snippets/csharp/VS_Snippets_CLR/Environment.GetEnvironmentVariables/CS/getenvironmentvariables.cs#1)] [!code-vb[Environment.GetEnvironmentVariables#1](~/samples/snippets/visualbasic/VS_Snippets_CLR/Environment.GetEnvironmentVariables/VB/getenvironmentvariables.vb#1)] ]]> The caller does not have the required permission to perform this operation. The buffer is out of memory. for the ability to read the names and values of environment variables. Associated enumeration: Method mscorlib 2.0.0.0 2.0.5.0 4.0.0.0 netstandard 2.0.0.0 System.Runtime.Extensions 4.2.0.0 4.2.1.0 System.Security.SecuritySafeCritical System.Collections.IDictionary One of the values. 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. A dictionary that contains all environment variable names and their values from the source specified by the parameter; otherwise, an empty dictionary if no environment variables are found. object. ### On Windows systems On Windows systems, the target parameter specifies whether the source is the current process, the registry key for the current user, or the registry key for the local machine. ### On macOS and Linux systems On macOS and Linux, only a target value of is supported. Per-process environment variables are inherited from the parent process (typically the shell) used to launch the dotnet process or are defined within the scope of the dotnet process itself. Once the dotnet process ends, these latter environment variables cease to exist. Per-machine and per-user environment variables are not supported. A target value of or returns an empty array. ## Examples The following example creates environment variables for the Process, User, and Machine targets, checks whether the operating system registry contains the User and Machine environment variables, then deletes the environment variables. [!code-cpp[environment.getsetenvar#1](~/samples/snippets/cpp/VS_Snippets_CLR/environment.getsetenvar/CPP/source.cpp#1)] [!code-csharp[environment.getsetenvar#1](~/samples/snippets/csharp/VS_Snippets_CLR/environment.getsetenvar/CS/gsev.cs#1)] [!code-vb[environment.getsetenvar#1](~/samples/snippets/visualbasic/VS_Snippets_CLR/environment.getsetenvar/VB/gsev.vb#1)] ]]> The caller does not have the required permission to perform this operation for the specified value of . contains an illegal value. for the ability to read the names and values of environment variables if is (Associated enumeration: ), or for full access to environment variables if is or (Associated enumeration: ). mscorlib 2.0.5.0 4.0.0.0 Gets the path to the system special folder that is identified by the specified enumeration. Method mscorlib 1.0.5000.0 2.0.0.0 2.0.5.0 4.0.0.0 netstandard 2.0.0.0 System.Runtime.Extensions 4.2.0.0 4.2.1.0 System.Security.SecuritySafeCritical System.String An enumerated constant that identifies a system special folder. Gets the path to the system special folder that is identified by the specified enumeration. The path to the specified system special folder, if that folder physically exists on your computer; otherwise, an empty string (""). A folder will not physically exist if the operating system did not create it, the existing folder was deleted, or the folder is a virtual directory, such as My Computer, which does not correspond to a physical path. enumeration; any other value throws an exception. For more information about special folders, see the [CSIDL](http://go.microsoft.com/fwlink/?LinkId=116664) values topic. ## Examples The following example demonstrates how to use the method to return and display the path associated with the folder parameter. [!code-cpp[Environment.GetFolderPath#1](~/samples/snippets/cpp/VS_Snippets_CLR/Environment.GetFolderPath/CPP/getfolderpath.cpp#1)] [!code-csharp[Environment.GetFolderPath#1](~/samples/snippets/csharp/VS_Snippets_CLR/Environment.GetFolderPath/CS/getfolderpath.cs#1)] [!code-vb[Environment.GetFolderPath#1](~/samples/snippets/visualbasic/VS_Snippets_CLR/Environment.GetFolderPath/VB/getfolderpath.vb#1)] ]]> is not a member of . The current platform is not supported. for access to the information in the path itself. Associated enumeration: Method mscorlib 2.0.5.0 4.0.0.0 netstandard 2.0.0.0 System.Runtime.Extensions 4.2.0.0 4.2.1.0 System.Security.SecuritySafeCritical System.String An enumerated constant that identifies a system special folder. Specifies options to use for accessing a special folder. Gets the path to the system special folder that is identified by the specified enumeration, and uses a specified option for accessing special folders. The path to the specified system special folder, if that folder physically exists on your computer; otherwise, an empty string (""). A folder will not physically exist if the operating system did not create it, the existing folder was deleted, or the folder is a virtual directory, such as My Computer, which does not correspond to a physical path. enumeration; any other value throws an exception. For more information about special folders, see the [CSIDL](http://go.microsoft.com/fwlink/?LinkId=116664) values topic. ]]> is not a member of for access to the information in the path itself. Associated enumeration: Method mscorlib 1.0.5000.0 2.0.0.0 2.0.5.0 4.0.0.0 netstandard 2.0.0.0 System.Runtime.Extensions 4.2.0.0 4.2.1.0 System.Security.SecuritySafeCritical System.String[] Returns an array of string containing the names of the logical drives on the current computer. An array of strings where each element contains the name of a logical drive. For example, if the computer's hard drive is the first logical drive, the first element returned is "C:\\". method. [!code-cpp[Environment.GetLogicalDrives#1](~/samples/snippets/cpp/VS_Snippets_CLR/Environment.GetLogicalDrives/CPP/getlogicaldrives.cpp#1)] [!code-csharp[Environment.GetLogicalDrives#1](~/samples/snippets/csharp/VS_Snippets_CLR/Environment.GetLogicalDrives/CS/getlogicaldrives.cs#1)] [!code-vb[Environment.GetLogicalDrives#1](~/samples/snippets/visualbasic/VS_Snippets_CLR/Environment.GetLogicalDrives/VB/getlogicaldrives.vb#1)] ]]> An I/O error occurs. The caller does not have the required permissions. for full access to the resource protected by this permission. Associated enumeration: Property System.Runtime.Extensions 4.0.0.0 4.0.10.0 4.1.0.0 4.2.0.0 4.2.1.0 mscorlib 1.0.5000.0 2.0.0.0 2.0.5.0 4.0.0.0 netstandard 2.0.0.0 get: System.Security.SecuritySafeCritical System.Boolean Gets a value that indicates whether the current application domain is being unloaded or the common language runtime (CLR) is shutting down. if the current application domain is being unloaded or the CLR is shutting down; otherwise, property returns true only after the finalizer thread has been started. When the property returns true, you can determine whether an application domain is being unloaded or the CLR itself is shutting down by calling the method. This method returns true if finalizers are called because the application domain is unloading or false if the CLR is shutting down. The property returns false if the finalizer thread has not been started. By using this property, you can determine whether to access static variables in your finalization code. If either an application domain or the CLR is shutting down, you cannot reliably access any object that has a finalization method and that is referenced by a static field. This is because these objects may have already been finalized. ]]> Property mscorlib 2.0.5.0 4.0.0.0 netstandard 2.0.0.0 System.Runtime.Extensions 4.2.0.0 4.2.1.0 get: System.Security.SecuritySafeCritical System.Boolean Determines whether the current operating system is a 64-bit operating system. if the operating system is 64-bit; otherwise, . To be added. Property mscorlib 2.0.5.0 4.0.0.0 netstandard 2.0.0.0 System.Runtime.Extensions 4.2.0.0 4.2.1.0 System.Boolean Determines whether the current process is a 64-bit process. if the process is 64-bit; otherwise, . To be added. Property System.Runtime.Extensions 4.1.0.0 4.2.0.0 4.2.1.0 mscorlib 1.0.5000.0 2.0.0.0 2.0.5.0 4.0.0.0 netstandard 2.0.0.0 get: System.Security.SecuritySafeCritical System.String Gets the NetBIOS name of this local computer. A string containing the name of this computer. The name of this computer cannot be obtained. for read access to the COMPUTERNAME environment variable. Associated enumeration: Property System.Runtime.Extensions 4.0.0.0 4.0.10.0 4.1.0.0 4.2.0.0 4.2.1.0 mscorlib 1.0.5000.0 2.0.0.0 2.0.5.0 4.0.0.0 netstandard 2.0.0.0 System.String Gets the newline string defined for this environment. A string containing "\r\n" for non-Unix platforms, or a string containing "\n" for Unix platforms. is a constant customized specifically for the current platform and implementation of the .NET Framework. For more information about the escape characters in the property value, see [Character Escapes](~/docs/standard/base-types/character-escapes-in-regular-expressions.md). The functionality provided by is often what is meant by the terms newline, line feed, line break, carriage return, CRLF, and end of line. can be used in conjunction with language-specific newline support such as the escape characters '\r' and '\n' in Microsoft C# and C/C++, or vbCrLf in Microsoft Visual Basic. is automatically appended to text processed by the and methods. ## Examples The following example displays three lines separated by newlines. [!code-cpp[environment.newline#1](~/samples/snippets/cpp/VS_Snippets_CLR/Environment.NewLine/CPP/newline.cpp#1)] [!code-csharp[environment.newline#1](~/samples/snippets/csharp/VS_Snippets_CLR/Environment.NewLine/CS/newline.cs#1)] [!code-vb[environment.newline#1](~/samples/snippets/visualbasic/VS_Snippets_CLR/Environment.NewLine/VB/newline.vb#1)] ]]> Property mscorlib 1.0.5000.0 2.0.0.0 2.0.5.0 4.0.0.0 netstandard 2.0.0.0 System.Runtime.Extensions 4.2.0.0 4.2.1.0 get: System.Security.SecuritySafeCritical System.OperatingSystem Gets an object that contains the current platform identifier and version number. An object that contains the platform identifier and version number. method. - Avoid writing code that depends on a reported operating system version. Instead, check for the availability of the features that your application needs. ]]> This property was unable to obtain the system version. -or- The obtained platform identifier is not a member of Property System.Runtime.Extensions 4.0.0.0 4.0.10.0 4.1.0.0 4.2.0.0 4.2.1.0 mscorlib 2.0.0.0 2.0.5.0 4.0.0.0 netstandard 2.0.0.0 get: System.Security.SecuritySafeCritical System.Int32 Gets the number of processors on the current machine. The 32-bit signed integer that specifies the number of processors on the current machine. There is no default. If the current machine contains multiple processor groups, this property returns the number of logical processors that are available for use by the common language runtime (CLR). property. [!code-cpp[environment.processorcount#1](~/samples/snippets/cpp/VS_Snippets_CLR/environment.processorcount/CPP/pc.cpp#1)] [!code-csharp[environment.processorcount#1](~/samples/snippets/csharp/VS_Snippets_CLR/environment.processorcount/CS/pc.cs#1)] [!code-vb[environment.processorcount#1](~/samples/snippets/visualbasic/VS_Snippets_CLR/environment.processorcount/VB/pc.vb#1)] ]]> System.Runtime.Extensions 4.0.10.0 4.1.0.0 4.2.0.0 Creates, modifies, or deletes an environment variable. Method System.Runtime.Extensions 4.0.10.0 4.1.0.0 4.2.0.0 4.2.1.0 mscorlib 2.0.0.0 2.0.5.0 4.0.0.0 netstandard 2.0.0.0 System.Security.SecuritySafeCritical System.Void The name of an environment variable. A value to assign to variable. Creates, modifies, or deletes an environment variable stored in the current process. overload with a value of for the target argument. If the value argument is not empty (see the discussion of deleting an environment variable later in this section for the definition of an empty value) and the environment variable named by the variable parameter does not exist, the environment variable is created and assigned the contents of value. If it does exist, its value is modified. Because the environment variable is defined in the environment block of the current process only, it does not persist after the process has ended. If variable contains a non-initial hexadecimal zero character, the characters before the zero character are considered the environment variable name and all subsequent characters are ignored. If value contains a non-initial hexadecimal zero character, the characters before the zero character are assigned to the environment variable and all subsequent characters are ignored. If value is empty and the environment variable named by variable exists, the environment variable is deleted. If variable does not exist, no error occurs even though the operation cannot be performed. value is considered empty under any of the following conditions: - It is null. - It is . - It consists of a single character whose value is U+0000. ## Examples The following example tests whether an environment variable named APPDOMAIN exists in the current process. If it does not, it creates it and sets its value to "True". If the value of the APPDOMAIN environment variable is "True", it calls the Message.Display method in a new application domain. Otherwise, it executes the Message.Display method in the current application domain. [!code-csharp[System.Environment.SetEnvironmentVariable#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.environment.setenvironmentvariable/cs/setenvironmentvariable1.cs#1)] [!code-vb[System.Environment.SetEnvironmentVariable#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.environment.setenvironmentvariable/vb/setenvironmentvariable1.vb#1)] If you run the example for the first time, the message "Executing in domain Domain2" displays to the console. If you set the environment variable from the command line by using the command: Set AppDomain=False the example displays the message "Executing in domain *exeName*.exe", where *exeName* is the name of the executable. The following example attempts to retrieve the value of an environment variable named Test1 from the process environment block. If the variable doesn't exist, the example creates the variable and retrieves its value. The example displays the value of the variable. If the example created the variable, it also calls the method with each member of the enumeration to establish that the variable can be retrieved only from the current process environment block. Finally, if the example created the variable, it deletes it. [!code-csharp[System.Environment.GetEnvironmentVariable#2](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.environment.getenvironmentvariable/cs/getenvironmentvariableex1.cs#2)] [!code-vb[System.Environment.GetEnvironmentVariable#2](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.environment.getenvironmentvariable/vb/getenvironmentvariableex1.vb#2)] ]]> is . contains a zero-length string, an initial hexadecimal zero character (0x00), or an equal sign ("="). -or- The length of or is greater than or equal to 32,767 characters. -or- An error occurred during the execution of this operation. The caller does not have the required permission to perform this operation. for full access to environment variables. Associated enumeration: Method mscorlib 2.0.0.0 2.0.5.0 4.0.0.0 netstandard 2.0.0.0 System.Runtime.Extensions 4.2.0.0 4.2.1.0 System.Security.SecuritySafeCritical System.Void The name of an environment variable. A value to assign to variable. One of the enumeration values that specifies the location of the environment variable. 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. method lets you define an environment variable that is available to the current process (the value). Environment variables that are unique to the current process environment block persist only until the process ends. In addition, on Windows systems only, the method lets you define an environment variable that is available to all processes that run on a machine (the value) and to all processes run by a user (the value). Per-machine and per-user environment variables are copied into the environment block of the current process. On .NET Core on maxOS and Linux systems, calls to the method with a value of or are ignored. If the value argument is not empty (see the discussion of deleting an environment variable later in this section for the definition of an empty value) and the environment variable named by the variable argument does not exist, the environment variable is created and assigned the contents of value. If it does exist, its value is modified. If variable contains a non-initial hexadecimal zero character, the characters before the zero character are considered the environment variable name and all subsequent characters are ignored. If value contains a non-initial hexadecimal zero character, the characters before the zero character are assigned to the environment variable and all subsequent characters are ignored. If value is empty and the environment variable named by variable exists, the environment variable is deleted. value is considered empty under any of the following conditions: - It is null. - It is . - It consists of a single character whose value is U+0000. If variable does not exist, no error occurs although the operation cannot be performed. Be careful when target is , because you can accidentally delete an environment variable that affects your entire local machine, not just the current process or user. ### EnvironmentVariableTarget.Machine and EnvironmentVariableTarget.User on Windows systems If target is , the environment variable is stored in the HKEY_CURRENT_USER\Environment key of the local computer's registry. It is also copied to instances of File Explorer that are running as the current user. The environment variable is then inherited by any new processes that the user launches from File Explorer. Similarly, if target is , the environment variable is stored in the HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment key of the local computer's registry. It is also copied to all instances of File Explorer. The environment variable is then inherited by any new processes that are launched from File Explorer. If target is or , other applications are notified of the set operation by a Windows WM_SETTINGCHANGE message. If target is or , we recommend that the length of value be less than 2048 characters. ## Examples The following example creates environment variables for the , , and targets, checks whether the operating system registry contains the user and machine environment variables, then deletes the environment variables. [!code-cpp[environment.getsetenvar#1](~/samples/snippets/cpp/VS_Snippets_CLR/environment.getsetenvar/CPP/source.cpp#1)] [!code-csharp[environment.getsetenvar#1](~/samples/snippets/csharp/VS_Snippets_CLR/environment.getsetenvar/CS/gsev.cs#1)] [!code-vb[environment.getsetenvar#1](~/samples/snippets/visualbasic/VS_Snippets_CLR/environment.getsetenvar/VB/gsev.vb#1)] ]]> is . contains a zero-length string, an initial hexadecimal zero character (0x00), or an equal sign ("="). -or- The length of is greater than or equal to 32,767 characters. -or- is not a member of the enumeration. -or- is or , and the length of is greater than or equal to 255. -or- is and the length of is greater than or equal to 32,767 characters. -or- An error occurred during the execution of this operation. The caller does not have the required permission to perform this operation. for full access to environment variables. Associated enumeration: Property System.Runtime.Extensions 4.0.10.0 4.1.0.0 4.2.0.0 4.2.1.0 mscorlib 1.0.5000.0 2.0.0.0 2.0.5.0 4.0.0.0 netstandard 2.0.0.0 get: System.Security.SecuritySafeCritical System.String Gets current stack trace information. A string containing stack trace information. This value can be . property lists method calls in reverse chronological order, that is, the most recent method call is described first, and one line of stack trace information is listed for each method call on the stack. However, the property might not report as many method calls as expected due to code transformations that occur during optimization. > [!NOTE] > For a hierarchical view of the stack trace information by class, use the class. The property formats the stack trace information for each method call as follows: "at FullClassName.MethodName(MethodParams) in FileName :line LineNumber " The literal "at" is preceded by three spaces, and the entire substring starting with "in" is omitted if debug symbols are not available. The placeholders, FullClassName, MethodName, MethodParams, FileName, and LineNumber, are replaced by actual values, and are defined as follows: FullClassName The full name of the class, including the namespace. MethodName The name of the method. MethodParams The list of parameter type/name pairs. Each pair is separated by a comma (","). This information is omitted if MethodName takes no parameters. FileName The name of the source file where the MethodName method is declared. This information is omitted if debug symbols are not available. LineNumber The number of the line in FileName that contains the source code from MethodName for the instruction that is on the call stack. This information is omitted if debug symbols are not available. The string terminates each line of the stack trace. ## Examples The following example demonstrates the property. [!code-cpp[environment.stacktrace#1](~/samples/snippets/cpp/VS_Snippets_CLR/Environment.StackTrace/CPP/stacktrace.cpp#1)] [!code-csharp[environment.stacktrace#1](~/samples/snippets/csharp/VS_Snippets_CLR/Environment.StackTrace/CS/stacktrace.cs#1)] [!code-vb[environment.stacktrace#1](~/samples/snippets/visualbasic/VS_Snippets_CLR/Environment.StackTrace/VB/stacktrace.vb#1)] ]]> for full access to the resource protected by the permission. Associated enumeration: Property mscorlib 1.0.5000.0 2.0.0.0 2.0.5.0 4.0.0.0 netstandard 2.0.0.0 System.Runtime.Extensions 4.2.0.0 4.2.1.0 get: System.Security.SecuritySafeCritical System.String Gets the fully qualified path of the system directory. A string containing a directory path. for access to the information in the path itself. Associated enumeration: Property mscorlib 2.0.5.0 4.0.0.0 netstandard 2.0.0.0 System.Runtime.Extensions 4.2.0.0 4.2.1.0 get: System.Security.SecuritySafeCritical System.Int32 Gets the number of bytes in the operating system's memory page. The number of bytes in the system memory page. option when you work with memory-mapped files. In Windows, this value is the dwPageSize member in the SYSTEM_INFO structure. ]]> for access to system and user environment variables. Associated exception: Property System.Runtime.Extensions 4.0.0.0 4.0.10.0 4.1.0.0 4.2.0.0 4.2.1.0 mscorlib 1.0.5000.0 2.0.0.0 2.0.5.0 4.0.0.0 netstandard 2.0.0.0 get: System.Security.SecuritySafeCritical System.Int32 Gets the number of milliseconds elapsed since the system started. A 32-bit signed integer containing the amount of time in milliseconds that has passed since the last time the computer was started. property is limited to the resolution of the system timer, which is typically in the range of 10 to 16 milliseconds. > [!IMPORTANT] > Because the value of the property value is a 32-bit signed integer, if the system runs continuously, will increment from zero to for approximately 24.9 days, then jump to , which is a negative number, then increment back to zero during the next 24.9 days. You can work around this issue by calling the Windows [GetTickCount](https://msdn.microsoft.com/library/windows/desktop/ms724408.aspx) function, which resets to zero after approximately 49.7 days, or by calling the [GetTickCount64](https://msdn.microsoft.com/library/windows/desktop/ms724411.aspx) function. is different from the property, which is the number of 100-nanosecond intervals that have elapsed since 1/1/0001, 12:00am. Use the property to obtain the current local date and time on this computer. ## Examples The following example demonstrates how to retrieve the positive range of values returned by the property. The property cycles between , which is a negative number, and once every 49.8 days. This code sample removes the sign bit to yield a nonnegative number that cycles between zero and once every 24.9 days. [!code-cpp[environment.tickcount#1](~/samples/snippets/cpp/VS_Snippets_CLR/Environment.TickCount/CPP/tickcount.cpp#1)] [!code-csharp[environment.tickcount#1](~/samples/snippets/csharp/VS_Snippets_CLR/Environment.TickCount/CS/tickcount.cs#1)] [!code-vb[environment.tickcount#1](~/samples/snippets/visualbasic/VS_Snippets_CLR/Environment.TickCount/VB/tickcount.vb#1)] ]]> Property mscorlib 1.0.5000.0 2.0.0.0 2.0.5.0 4.0.0.0 netstandard 2.0.0.0 System.Runtime.Extensions 4.2.0.0 4.2.1.0 get: System.Security.SecuritySafeCritical System.String Gets the network domain name associated with the current user. The network domain name associated with the current user. property to obtain the user's domain name without the user name, and the property to obtain the user name without the domain name. For example, if a user's domain name and user name are CORPORATENETWORK\john, the property returns "CORPORATENETWORK". The property first attempts to get the domain name component of the Windows account name for the current user. If that attempt fails, this property attempts to get the domain name associated with the user name provided by the property. If that attempt fails because the host computer is not joined to a domain, then the host computer name is returned. ]]> The operating system does not support retrieving the network domain name. The network domain name cannot be retrieved. for read access to the USERDOMAIN environment variable. Associated enumeration: Property mscorlib 1.0.5000.0 2.0.0.0 2.0.5.0 4.0.0.0 netstandard 2.0.0.0 System.Runtime.Extensions 4.2.0.0 4.2.1.0 get: System.Security.SecuritySafeCritical System.Boolean Gets a value indicating whether the current process is running in user interactive mode. if the current process is running in user interactive mode; otherwise, . property reports false for a Windows process or a service like IIS that runs without a user interface. If this property is false, do not display modal dialogs or message boxes because there is no graphical user interface for the user to interact with. ## Examples The following example displays whether the current process is running in user interactive mode. [!code-cpp[Environment.UserInteractive#1](~/samples/snippets/cpp/VS_Snippets_CLR/Environment.UserInteractive/CPP/userinteractive.cpp#1)] [!code-csharp[Environment.UserInteractive#1](~/samples/snippets/csharp/VS_Snippets_CLR/Environment.UserInteractive/CS/userinteractive.cs#1)] [!code-vb[Environment.UserInteractive#1](~/samples/snippets/visualbasic/VS_Snippets_CLR/Environment.UserInteractive/VB/userinteractive.vb#1)] ]]> Property mscorlib 1.0.5000.0 2.0.0.0 2.0.5.0 4.0.0.0 netstandard 2.0.0.0 System.Runtime.Extensions 4.2.0.0 4.2.1.0 get: System.Security.SecuritySafeCritical System.String Gets the user name of the person who is currently logged on to the operating system. The user name of the person who is logged on to the operating system. property to identify the user on the current thread, to the system and application for security or access purposes. It can also be used to customize a particular application for each user. On Windows the property wraps a call to the Windows [GetUserName](http://msdn.microsoft.com/library/windows/desktop/ms724432.aspx) function. The domain account credentials for a user are formatted as the user's domain name, the '\\' character, and user name. Use the property to obtain the user's domain name and the property to obtain the user name. On Unix platforms the property wraps a call to the getpwuid_r function. If an ASP.NET application runs in a development environment, the property returns the name of the current user. In a published ASP.NET application, this property returns the name of the application pool account (such as Default AppPool). ## Examples The following example displays the user name of the person who started the current thread. [!code-cpp[Environment.UserName#1](~/samples/snippets/cpp/VS_Snippets_CLR/Environment.UserName/CPP/username.cpp#1)] [!code-csharp[Environment.UserName#1](~/samples/snippets/csharp/VS_Snippets_CLR/Environment.UserName/CS/username.cs#1)] [!code-vb[Environment.UserName#1](~/samples/snippets/visualbasic/VS_Snippets_CLR/Environment.UserName/VB/username.vb#1)] ]]> for read access to the USERNAME environment variable. Associated enumeration: Property mscorlib 1.0.5000.0 2.0.0.0 2.0.5.0 4.0.0.0 netstandard 2.0.0.0 System.Runtime.Extensions 4.2.0.0 4.2.1.0 System.Version Gets a object that describes the major, minor, build, and revision numbers of the common language runtime. An object that displays the version of the common language runtime. property returns a object whose string representation has the form 4.0.30319.xxxxx. For the .NET Framework 4.6 and later versions, it has the form 4.0.30319.42000. > [!WARNING] > For the [!INCLUDE[net_v45](~/includes/net-v45-md.md)] and later, we do not recommend using the property to detect the version of the runtime; instead, you can determine the version of the common language runtime by querying the registry. For more information, see [How to: Determine Which .NET Framework Versions Are Installed](~/docs/framework/migration-guide/how-to-determine-which-versions-are-installed.md). For more information about the version of the common language runtime that is installed with each version of the .NET Framework, see [Versions and Dependencies](~/docs/framework/migration-guide/versions-and-dependencies.md). ## Examples The following example displays the version of the common language runtime. (The version is omitted from the example output for security reasons.) [!code-cpp[Environment.Version#1](~/samples/snippets/cpp/VS_Snippets_CLR/Environment.Version/CPP/version.cpp#1)] [!code-csharp[Environment.Version#1](~/samples/snippets/csharp/VS_Snippets_CLR/Environment.Version/CS/version.cs#1)] [!code-vb[Environment.Version#1](~/samples/snippets/visualbasic/VS_Snippets_CLR/Environment.Version/VB/version.vb#1)] ]]> Property mscorlib 1.0.5000.0 2.0.0.0 2.0.5.0 4.0.0.0 netstandard 2.0.0.0 System.Runtime.Extensions 4.2.0.0 4.2.1.0 get: System.Security.SecuritySafeCritical System.Int64 Gets the amount of physical memory mapped to the process context. A 64-bit signed integer containing the number of bytes of physical memory mapped to the process context. for full access to the resource protected by this permission. Associated enumeration: