-
Notifications
You must be signed in to change notification settings - Fork 13
/
env.cs
48 lines (40 loc) · 1.33 KB
/
env.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Source: https://docs.microsoft.com/en-us/dotnet/api/system.environment.getenvironmentvariables?view=netframework-4.8
// Added sorting to match the output of the native Windows "set"
// To Compile:
// C:\Windows\Microsoft.NET\Framework\v2.0.50727\csc.exe /t:exe /out:env.exe env.cs
using System;
using System.Collections;
using System.Collections.Generic;
class Env
{
public static void Main(string[] args)
{
try
{
if (args.Length > 0 && args[0] == "/?")
{
Console.WriteLine(@"Displays environment variables (in alphabetical order)
USAGE:
env.exe [/?]");
return;
}
SortedDictionary<string, string> envVars = new SortedDictionary<string, string>();
foreach (DictionaryEntry de in Environment.GetEnvironmentVariables())
{
envVars.Add((string)de.Key, (string)de.Value);
}
foreach (KeyValuePair<string, string> kvp in envVars)
{
Console.WriteLine("{0}={1}", kvp.Key, kvp.Value);
}
}
catch (Exception e)
{
Console.Error.WriteLine("[-] ERROR: {0}", e.Message.Trim());
}
finally
{
Console.WriteLine("\nDONE");
}
}
}