Skip to content

Commit 38ab0c7

Browse files
authored
Updates for setting empty env variable (#10100)
1 parent a76afd3 commit 38ab0c7

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

xml/System/Environment.xml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,15 +2014,14 @@ If the executable is renamed or deleted before this property is first accessed,
20142014
20152015
On Unix-like systems, calls to the <xref:System.Environment.SetEnvironmentVariable%28System.String%2CSystem.String%29> method have no effect on any native libraries that are, or will be, loaded. (Conversely, in-process environment modifications made by native libraries aren't seen by managed callers.)
20162016
2017-
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.
2017+
If the `value` argument is not `null` and the environment variable named by the `variable` parameter doesn't 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.
20182018
20192019
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.
20202020
20212021
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.
20222022
2023-
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:
2023+
If `value` is `null` (or empty in versions prior to .NET 9) and the environment variable named by `variable` exists, the environment variable is deleted. If `variable` doesn't exist, no error occurs even though the operation cannot be performed. `value` is considered empty under any of the following conditions:
20242024
2025-
- It is `null`.
20262025
- It is <xref:System.String.Empty?displayProperty=nameWithType>.
20272026
- It consists of a single character whose value is U+0000.
20282027
@@ -2126,19 +2125,18 @@ On Unix-like systems, calls to the <xref:System.Environment.SetEnvironmentVariab
21262125
21272126
On Unix-like systems, calls to the <xref:System.Environment.SetEnvironmentVariable%28System.String%2CSystem.String%2CSystem.EnvironmentVariableTarget%29> method with a value of <xref:System.EnvironmentVariableTarget.Process?displayProperty=nameWithType> have no effect on any native libraries that are, or will be, loaded. (Conversely, in-process environment modifications made by native libraries aren't seen by managed callers.)
21282127
2129-
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.
2128+
If the `value` argument is not `null` and the environment variable named by the `variable` argument doesn't exist, the environment variable is created and assigned the contents of `value`. If it does exist, its value is modified.
21302129
21312130
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.
21322131
21332132
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.
21342133
2135-
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:
2134+
If `value` is `null` (or empty in versions prior to .NET 9) and the environment variable named by `variable` exists, the environment variable is deleted. `value` is considered empty under any of the following conditions:
21362135
2137-
- It is `null`.
2138-
- It is <xref:System.String.Empty?displayProperty=nameWithType>.
2139-
- It consists of a single character whose value is U+0000.
2136+
- It is <xref:System.String.Empty?displayProperty=nameWithType>.
2137+
- It consists of a single character whose value is U+0000.
21402138
2141-
If `variable` does not exist, no error occurs although the operation cannot be performed. Be careful when `target` is <xref:System.EnvironmentVariableTarget.Machine>, because you can accidentally delete an environment variable that affects your entire local machine, not just the current process or user.
2139+
If `variable` doesn't exist, no error occurs although the operation can't be performed. Be careful when `target` is <xref:System.EnvironmentVariableTarget.Machine>, because you can accidentally delete an environment variable that affects your entire local machine, not just the current process or user.
21422140
21432141
### EnvironmentVariableTarget.Machine and EnvironmentVariableTarget.User on Windows systems
21442142
@@ -2562,7 +2560,7 @@ The following example creates environment variables for the <xref:System.Environ
25622560
<format type="text/markdown"><![CDATA[
25632561
25642562
## Remarks
2565-
The domain account credentials for a user are formatted as the user's domain name, the '\\' character, and user name. Use the <xref:System.Environment.UserDomainName%2A> property to obtain the user's domain name without the user name, and the <xref:System.Environment.UserName%2A> 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 <xref:System.Environment.UserDomainName%2A> property returns "CORPORATENETWORK".
2563+
The domain account credentials for a user are formatted as the user's domain name, the '\\' character, and user name. Use the <xref:System.Environment.UserDomainName%2A> property to obtain the user's domain name without the user name, and the <xref:System.Environment.UserName%2A> 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 <xref:System.Environment.UserDomainName%2A> property returns "CORPORATENETWORK".
25662564
25672565
The <xref:System.Environment.UserDomainName%2A> 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 <xref:System.Environment.UserName%2A> property. If that attempt fails because the host computer is not joined to a domain, then the host computer name is returned.
25682566

0 commit comments

Comments
 (0)