86 lpVersionInfo.dwMajorVersion = 6;
87 lpVersionInfo.dwMinorVersion = 2;
88 lpVersionInfo.wServicePackMajor = 0;
89 lpVersionInfo.wServicePackMinor = 0;
149 if (
value.Length == 0)
181 if (
text.Length == 0)
209 if (operatingSystem ==
null)
214 return operatingSystem;
224 int num = readOnlySpan.IndexOfAny(
'-',
'+',
' ');
227 readOnlySpan = readOnlySpan.
Slice(0, num);
252 Span<char> initialBuffer = stackalloc
char[40];
256 int num = span.IndexOf(
'\\');
259 span = span.
Slice(num + 1);
271 Span<char> initialBuffer = stackalloc
char[40];
275 int num = span.IndexOf(
'\\');
278 builder.Length = num;
281 initialBuffer = stackalloc
char[64];
283 uint cchReferencedDomainName = (uint)valueStringBuilder.
Capacity;
290 if (lastPInvokeError != 122)
297 valueStringBuilder.Length = (int)cchReferencedDomainName;
298 return valueStringBuilder.
ToString();
306 Span<char> initialBuffer = stackalloc
char[260];
308 uint currentDirectory;
313 if (currentDirectory == 0)
317 outputBuilder.Length = (int)currentDirectory;
318 if (outputBuilder.
AsSpan().Contains(
'~'))
321 outputBuilder.Dispose();
341 return lpSystemInfo.dwPageSize;
351 Span<char> initialBuffer = stackalloc
char[32];
353 uint systemDirectoryW;
358 if (systemDirectoryW == 0)
362 valueStringBuilder.Length = (int)systemDirectoryW;
363 return valueStringBuilder.
ToString();
375 uint lpnLengthNeeded = 0u;
378 return (uSEROBJECTFLAGS.
dwFlags & 1) != 0;
401 private static extern void _Exit(
int exitCode);
404 public static void Exit(
int exitCode)
411 public static extern void FailFast(
string? message);
443 if (variable ==
null)
456 if (variable ==
null)
498 if (name.Length == 0)
532 EnvironmentVariableTarget.Machine =>
true,
533 EnvironmentVariableTarget.User =>
false,
540 if (variable ==
null)
544 if (variable.Length == 0)
548 if (variable[0] ==
'\0')
552 if (variable.Contains(
'='))
556 if (
string.IsNullOrEmpty(
value) ||
value[0] ==
'\0')
565 return registryKey?.GetValue(variable) as
string;
570 if (!fromMachine && variable.Length >= 255)
576 if (registryKey !=
null)
580 registryKey.
DeleteValue(variable, throwOnMissingValue:
false);
588 fixed (
char* ptr = &
"Environment".GetPinnableReference())
600 if (registryKey !=
null)
603 foreach (
string text in valueNames)
626 name =
"System\\CurrentControlSet\\Control\\Session Manager\\Environment";
631 name =
"Environment";
633 return registryKey.
OpenSubKey(name, writable);
643 builder.EnsureCapacity(checked((
int)lpnSize));
649 builder.Length = (int)lpnSize;
658 folderGuid =
"{3EB685DB-65F9-4CF6-A03A-E3EF65729F3D}";
661 folderGuid =
"{62AB5D82-FDC1-4DC3-A9DD-070D1D495D97}";
664 folderGuid =
"{F1B32785-6FBA-4FCF-9D55-7B8E7F157091}";
667 folderGuid =
"{2B0F765D-C0E9-4171-908E-08A611B84FF6}";
670 folderGuid =
"{B4BFCC3A-DB2C-424C-B029-7FE99A87C641}";
673 folderGuid =
"{1777F761-68AD-4D8A-87BD-30B759FA33DD}";
676 folderGuid =
"{D9DC8A3B-B784-432E-A781-5A1130A75963}";
679 folderGuid =
"{352481E8-33BE-4251-BA85-6007CAEDCF9D}";
682 folderGuid =
"{A77F5D77-2E2B-44C3-A6A2-ABA601054A51}";
685 folderGuid =
"{0AC0837C-BBF8-452A-850D-79D08E667CA7}";
688 folderGuid =
"{4BD8D571-6D19-48D3-BE97-422220080E43}";
691 folderGuid =
"{33E28130-4E1E-4676-835A-98395C3BC3BB}";
694 folderGuid =
"{18989B1D-99B5-455B-841C-AB7C74E4DDFC}";
697 folderGuid =
"{AE50C081-EBD2-438A-8655-8A092E34987A}";
700 folderGuid =
"{8983036C-27C0-404B-8F08-102D10DCFD74}";
703 folderGuid =
"{625B53C3-AB48-4EC1-BA1F-A1EF4146FC19}";
706 folderGuid =
"{B97D20BB-F46A-4C97-BA10-5E3608430854}";
709 folderGuid =
"{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}";
712 folderGuid =
"{A63293E8-664E-48DB-A079-DF759E0509F7}";
715 folderGuid =
"{B4BFCC3A-DB2C-424C-B029-7FE99A87C641}";
718 folderGuid =
"{FDD39AD0-238F-46AF-ADB4-6C85480369C7}";
721 folderGuid =
"{905e63b6-c1bf-494e-b29c-65b732d3d21a}";
724 folderGuid =
"{F7F1ED05-9F6D-47A2-AAAE-29D317C6F066}";
727 folderGuid =
"{724EF170-A42D-4FEF-9F26-B60E846FBA4F}";
730 folderGuid =
"{9E52AB10-F80D-49DF-ACB8-4330F5687855}";
733 folderGuid =
"{D0384E7D-BAC3-4797-8F14-CBA229B392B5}";
736 folderGuid =
"{ED4824AF-DCE4-45A8-81E2-FC7965083634}";
739 folderGuid =
"{3214FAB5-9757-4298-BB61-92A9DEAA44FF}";
742 folderGuid =
"{C1BAE2D0-10DF-4334-BEDD-7AA20B227A9D}";
745 folderGuid =
"{B6EBFB86-6907-413C-9AF7-4FC2ABF07CC5}";
748 folderGuid =
"{A4115719-D62E-491D-AA7C-E74B8BE3B067}";
751 folderGuid =
"{0139D44E-6AFE-49F2-8690-3DAFCAE6FFB8}";
754 folderGuid =
"{82A5EA35-D9CD-47C5-9629-E15D2F714E6E}";
757 folderGuid =
"{C4AA340D-F20F-4863-AFEF-F87EF2E6BA25}";
760 folderGuid =
"{B94237E7-57AC-4347-9151-B08C6C32D1F7}";
763 folderGuid =
"{2400183A-6185-49FB-A2D8-4A392A602BA3}";
766 folderGuid =
"{FD228CB7-AE11-4AE3-864C-16F3910AB8FE}";
769 folderGuid =
"{C5ABBF53-E17F-4121-8900-86626FC2C973}";
772 folderGuid =
"{76FC4E2D-D6AD-4519-A663-37BD56068185}";
775 folderGuid =
"{5E6C858F-0E22-4760-9AFE-EA3317B67173}";
778 folderGuid =
"{DE974D24-D9C6-4D3E-BF91-F4455120B917}";
781 folderGuid =
"{7C5A40EF-A0FB-4BFC-874A-C0F2E0B9FA8E}";
784 folderGuid =
"{8AD10C31-2ADB-4296-A8F7-E4701232C972}";
787 folderGuid =
"{2A00375E-224C-49DE-B8D1-440DF7EF3DDC}";
790 folderGuid =
"{D65231B0-B2F1-4857-A4CE-A8E7C6EA7D27}";
793 folderGuid =
"{F38BF404-1D43-42F2-9305-67DE0B28FC23}";
818 Span<char> initialBuffer = stackalloc
char[128];
829 valueStringBuilder.Length = (int)(num - 1);
830 return valueStringBuilder.
ToString();
841 Span<char> initialBuffer = stackalloc
char[260];
848 if (moduleFileName == 0)
852 valueStringBuilder.Length = (int)moduleFileName;
853 return valueStringBuilder.
ToString();
862 Version version =
new Version((
int)osvi.dwMajorVersion, (
int)osvi.dwMinorVersion, (
int)osvi.dwBuildNumber, 0);
863 if (osvi.szCSDVersion[0] ==
'\0')
872 Span<char> initialBuffer = stackalloc
char[128];
874 uint environmentVariable;
884 valueStringBuilder.Length = (int)environmentVariable;
885 return valueStringBuilder.
ToString();
893 switch (lastPInvokeError)
911 if (environmentStringsW ==
null)
918 char* ptr = environmentStringsW;
926 int num = span.IndexOf(
'=');
939 ptr += span.Length + 1;
object GetValue(string name)
void DeleteValue(string name, bool throwOnMissingValue)
void SetValue(string name, string value)
RegistryKey OpenSubKey(string name)
static readonly RegistryKey LocalMachine
static readonly RegistryKey CurrentUser
static bool LookupAccountNameW(string lpSystemName, ref char lpAccountName, ref byte Sid, ref uint cbSid, ref char ReferencedDomainName, ref uint cchReferencedDomainName, out uint peUse)
static bool SetEnvironmentVariable(string lpName, string lpValue)
static ulong VerSetConditionMask(ulong ConditionMask, uint TypeMask, byte Condition)
static bool SetCurrentDirectory(string path)
static uint GetEnvironmentVariable(string lpName, ref char lpBuffer, uint nSize)
static bool GetProcessMemoryInfo(IntPtr Process, ref PROCESS_MEMORY_COUNTERS ppsmemCounters, uint cb)
static uint GetSystemDirectoryW(ref char lpBuffer, uint uSize)
static void GetSystemInfo(out SYSTEM_INFO lpSystemInfo)
static uint GetCurrentProcessId()
static int GetComputerName(ref char lpBuffer, ref uint nSize)
static uint ExpandEnvironmentStrings(string lpSrc, ref char lpDst, uint nSize)
static string GetMessage(int errorCode)
static unsafe char * GetEnvironmentStringsW()
static uint GetModuleFileName(IntPtr hModule, ref char lpFilename, uint nSize)
static unsafe BOOL FreeEnvironmentStringsW(char *lpszEnvironmentBlock)
static bool VerifyVersionInfoW(ref OSVERSIONINFOEX lpVersionInfo, uint dwTypeMask, ulong dwlConditionMask)
static uint GetCurrentDirectory(uint nBufferLength, ref char lpBuffer)
static IntPtr GetCurrentProcess()
static unsafe int RtlGetVersionEx(out RTL_OSVERSIONINFOEX osvi)
static BOOLEAN GetUserNameExW(int NameFormat, ref char lpNameBuffer, ref uint lpnSize)
static int SHGetKnownFolderPath([MarshalAs(UnmanagedType.LPStruct)] Guid rfid, uint dwFlags, IntPtr hToken, out string ppszPath)
static IntPtr SendMessageTimeout(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam, int flags, int timeout, out IntPtr pdwResult)
static IntPtr GetProcessWindowStation()
static unsafe bool GetUserObjectInformationW(IntPtr hObj, int nIndex, void *pvBuffer, uint nLength, ref uint lpnLengthNeeded)
virtual void Add(object key, object? value)
static bool IsDefined(Type enumType, object value)
static readonly bool IsWindows8OrAbove
static unsafe bool GetIsWindows8OrAbove()
static string[] GetLogicalDrives()
static string[] s_commandLineArgs
static volatile OperatingSystem s_osVersion
static string SystemDirectory
static int SystemPageSize
static void _Exit(int exitCode)
static void FailFast(string? message)
static volatile int s_processId
static string GetEnvironmentVariableCore(string variable)
static int GetProcessId()
static string CurrentDirectory
static string GetFolderPathCore(SpecialFolder folder, SpecialFolderOption option)
static string CurrentDirectoryCore
static IDictionary GetEnvironmentVariablesFromRegistry(bool fromMachine)
static string UserDomainName
static string GetEnvironmentVariableFromRegistry(string variable, bool fromMachine)
static void SetCommandLineArgs(string[] cmdLineArgs)
static unsafe void SetEnvironmentVariableFromRegistry(string variable, string value, bool fromMachine)
static string GetProcessPath()
static int GetProcessorCount()
static void GetUserName(ref ValueStringBuilder builder)
static string GetResourceStringLocal(string key)
static string GetFolderPath(SpecialFolder folder, SpecialFolderOption option)
static bool HasShutdownStarted
static IDictionary GetEnvironmentVariables(EnvironmentVariableTarget target)
static void ValidateVariableAndValue(string variable, ref string value)
static unsafe bool UserInteractive
static unsafe IDictionary GetEnvironmentVariables()
static int ProcessorCount
static unsafe long WorkingSet
static string ExpandEnvironmentVariables(string name)
static bool IsSingleProcessor
static string CommandLine
static string[] GetCommandLineArgsNative()
static int CurrentManagedThreadId
static volatile string s_processPath
static bool Is64BitOperatingSystem
static ? string GetEnvironmentVariable(string variable)
static void SetEnvironmentVariable(string variable, string? value, EnvironmentVariableTarget target)
static string GetFolderPath(SpecialFolder folder)
static void SetEnvironmentVariable(string variable, string? value)
static bool Is64BitProcess
static RegistryKey OpenEnvironmentKeyIfExists(bool fromMachine, bool writable)
static string[] GetCommandLineArgs()
static void FailFast(string? message, Exception? exception, string? errorMessage)
static unsafe OperatingSystem GetOSVersion()
static string ExpandEnvironmentVariablesCore(string name)
static void SetEnvironmentVariableCore(string variable, string value)
static string GetKnownFolderPath(string folderGuid, SpecialFolderOption option)
static void FailFast(string? message, Exception? exception)
static ? string GetEnvironmentVariable(string variable, EnvironmentVariableTarget target)
static void Exit(int exitCode)
static ? string ProcessPath
static bool ValidateAndConvertRegistryTarget(EnvironmentVariableTarget target)
static OperatingSystem OSVersion
static string MachineName
static bool IsWindows8OrAbove
static string[] GetLogicalDrives()
static string TryExpandShortFileName(ref ValueStringBuilder outputBuilder, string originalPath)
static Exception GetExceptionForLastWin32Error(string path="")
static string GetMessage(int errorCode)
static Exception GetExceptionForWin32Error(int errorCode, string path="")
static string Paste(IEnumerable< string > arguments, bool pasteFirstArgumentUsingArgV0Rules)
static int GetLastPInvokeError()
static unsafe ReadOnlySpan< char > CreateReadOnlySpanFromNullTerminated(char *value)
static string InvalidOperation_ComputerName
static string Arg_EnumIllegalVal
static string Format(string resourceFormat, object p1)
static string Argument_StringZeroLength
static string Argument_PathEmpty
static string Argument_IllegalEnvVarName
static string GetResourceString(string resourceKey)
static string Argument_StringFirstCharIsZero
static string Argument_LongEnvVarValue
static string InvalidOperation_GetVersion
static int CompareExchange(ref int location1, int value, int comparand)
static bool TryParse([NotNullWhen(true)] string? input, [NotNullWhen(true)] out Version? result)
EnvironmentVariableTarget
static readonly IntPtr Zero
ReadOnlySpan< T > Slice(int start)
override string ToString()
ref char GetPinnableReference()
void EnsureCapacity(int capacity)
override string ToString()
ReadOnlySpan< char > AsSpan(bool terminate)