The Labs \ Source Viewer \ SSCLI \ System.Runtime.InteropServices \ RuntimeEnvironment

  1. // ==++==
  2. //
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. //
  14. // ==--==
  15. /*=============================================================================
  16. **
  17. ** Class: RuntimeEnvironment
  18. **
  19. **
  20. ** Purpose: Runtime information
  21. **         
  22. **
  23. =============================================================================*/
  24. using System;
  25. using System.Text;
  26. using System.IO;
  27. using System.Runtime.CompilerServices;
  28. using System.Security.Permissions;
  29. using System.Reflection;
  30. using Microsoft.Win32;
  31. namespace System.Runtime.InteropServices
  32. {
  33.     [System.Runtime.InteropServices.ComVisible(true)]
  34.     public class RuntimeEnvironment
  35.     {
  36.        
  37.         [MethodImplAttribute(MethodImplOptions.InternalCall)]
  38.         static internal extern string GetModuleFileName();
  39.        
  40.         [MethodImplAttribute(MethodImplOptions.InternalCall)]
  41.         static internal extern string GetDeveloperPath();
  42.        
  43.         [MethodImplAttribute(MethodImplOptions.InternalCall)]
  44.         static internal extern string GetHostBindingFile();
  45.        
  46.         [DllImport(Win32Native.SHIM, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
  47.         private static extern int GetCORVersion(StringBuilder sb, int BufferLength, ref int retLength);
  48.        
  49.         [MethodImplAttribute(MethodImplOptions.InternalCall)]
  50.         public static extern bool FromGlobalAccessCache(Assembly a);
  51.        
  52.         public static string GetSystemVersion()
  53.         {
  54.             StringBuilder s = new StringBuilder(256);
  55.             int retLength = 0;
  56.             if (GetCORVersion(s, 256, ref retLength) == 0)
  57.                 return s.ToString();
  58.             else
  59.                 return null;
  60.         }
  61.        
  62.         public static string GetRuntimeDirectory()
  63.         {
  64.             string dir = GetRuntimeDirectoryImpl();
  65.             new FileIOPermission(FileIOPermissionAccess.PathDiscovery, dir).Demand();
  66.             return dir;
  67.         }
  68.        
  69.         [MethodImplAttribute(MethodImplOptions.InternalCall)]
  70.         static internal extern string GetRuntimeDirectoryImpl();
  71.        
  72.         // Returns the system ConfigurationFile
  73.         public static string SystemConfigurationFile {
  74.             get {
  75.                 StringBuilder sb = new StringBuilder(Path.MAX_PATH);
  76.                 sb.Append(GetRuntimeDirectory());
  77.                 sb.Append(AppDomainSetup.RuntimeConfigurationFile);
  78.                 string path = sb.ToString();
  79.                
  80.                 // Do security check
  81.                 new FileIOPermission(FileIOPermissionAccess.PathDiscovery, path).Demand();
  82.                
  83.                 return path;
  84.             }
  85.         }
  86.        
  87.     }
  88. }

Developer Fusion