C# tips and tricks 13 – How to Access various System Environment settings & OS related information.

0
1



C# Environment Class:

Provides information about, and means to manipulate, the current environment and platform.
Getting and setting various operating system related information.

Current Directory
Machine Name
New Line
OS Version
System Directory
User Domain Name
User Name
Get Environment Variable
temporary directory
Get Environment Variables
Special Folder
Logical Drives

using System;
using System.Collections;

class Sample
{
public static void Main()
{

Console.WriteLine(“CommandLine: {0}”, Environment.CommandLine);

String[] arguments = Environment.GetCommandLineArgs();
Console.WriteLine(“GetCommandLineArgs: {0}”, String.Join(“, “, arguments));

Console.WriteLine(“CurrentDirectory: {0}”, Environment.CurrentDirectory);

Console.WriteLine(“MachineName: {0}”, Environment.MachineName);

Console.WriteLine(“NewLine: {0} first line{0} second line{0} third line”,
Environment.NewLine);

Console.WriteLine(“OSVersion: {0}”, Environment.OSVersion.ToString());

Console.WriteLine(“SystemDirectory: {0}”, Environment.SystemDirectory);

Console.WriteLine(“UserDomainName: {0}”, Environment.UserDomainName);

Console.WriteLine(“UserName: {0}”, Environment.UserName);

Console.WriteLine(“Version: {0}”, Environment.Version.ToString());

Console.WriteLine(“GetEnvironmentVariable: {0} My temporary directory is {1}.”, nl,
Environment.GetEnvironmentVariable(“TEMP”));

Console.WriteLine(“GetEnvironmentVariables: “);
IDictionary environmentVariables = Environment.GetEnvironmentVariables();
foreach (DictionaryEntry de in environmentVariables)
{
Console.WriteLine(” {0} = {1}”, de.Key, de.Value);
}

Console.WriteLine(“GetFolderPath: {0}”,
Environment.GetFolderPath(Environment.SpecialFolder.System));

String[] drives = Environment.GetLogicalDrives();
Console.WriteLine(“GetLogicalDrives: {0}”, String.Join(“, “, drives));
}
}

Nguồn:https://wijstaanvooronzegrondrechten.org/

Xem Thêm Bài Viết Khác:https://wijstaanvooronzegrondrechten.org/cong-nghe

LEAVE A REPLY

Please enter your comment!
Please enter your name here