diff --git a/src/System.Management.Automation/CoreCLR/CorePsExtensions.cs b/src/System.Management.Automation/CoreCLR/CorePsExtensions.cs
index 5674327cd..59a864d01 100644
--- a/src/System.Management.Automation/CoreCLR/CorePsExtensions.cs
+++ b/src/System.Management.Automation/CoreCLR/CorePsExtensions.cs
@@ -893,13 +893,10 @@ namespace System.Management.Automation
return GetEnvironmentVariables();
}
- if (!Platform.HasRegistrySupport())
- {
- // Porting note: Does not throw a PlatformUnsupported because
- // GetEnvironmentVariable cannot throw, and we want the same interface.
- return null;
- }
-
+#if LINUX
+ return null;
+#else
+
if( target == EnvironmentVariableTarget.Machine)
{
using (RegistryKey environmentKey =
@@ -916,6 +913,7 @@ namespace System.Management.Automation
return GetRegistryKeyNameValuePairs(environmentKey);
}
}
+#endif
}
///
@@ -956,13 +954,9 @@ namespace System.Management.Automation
return System.Environment.GetEnvironmentVariable(variable);
}
- if (!Platform.HasRegistrySupport())
- {
- // Porting note: This cannot throw since it would otherwise throw while
- // creating a runspace. Returning null is appropriate to signal that there
- // is no value for a registry key with no registry.
- return null;
- }
+#if LINUX
+ return null;
+#else
if (target == EnvironmentVariableTarget.Machine)
{
@@ -985,6 +979,7 @@ namespace System.Management.Automation
return value;
}
}
+#endif
}
#endregion EnvironmentVariable_Extensions
diff --git a/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs b/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs
index 35ba1a55e..134291ed6 100644
--- a/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs
+++ b/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs
@@ -217,12 +217,6 @@ namespace System.Management.Automation
}
- // Linux does not have a registry
- internal static bool HasRegistrySupport()
- {
- return IsWindows;
- }
-
// Linux does not have PowerShell execution policies
internal static bool HasExecutionPolicy()
{
diff --git a/src/System.Management.Automation/engine/CommandDiscovery.cs b/src/System.Management.Automation/engine/CommandDiscovery.cs
index 2d0e2e917..23c95b432 100644
--- a/src/System.Management.Automation/engine/CommandDiscovery.cs
+++ b/src/System.Management.Automation/engine/CommandDiscovery.cs
@@ -1903,13 +1903,9 @@ namespace System.Management.Automation
///
internal static string GetShellPathFromRegistry(string shellID)
{
- if (!Platform.HasRegistrySupport())
- {
- return null;
- }
-
string result = null;
+#if !LINUX
try
{
RegistryKey shellKey = Registry.LocalMachine.OpenSubKey(Utils.GetRegistryConfigurationPath(shellID));
@@ -1935,6 +1931,7 @@ namespace System.Management.Automation
catch (ArgumentException)
{
}
+#endif
return result;
}
diff --git a/src/System.Management.Automation/engine/PSVersionInfo.cs b/src/System.Management.Automation/engine/PSVersionInfo.cs
index d500e7e85..92aaee14e 100644
--- a/src/System.Management.Automation/engine/PSVersionInfo.cs
+++ b/src/System.Management.Automation/engine/PSVersionInfo.cs
@@ -103,13 +103,9 @@ namespace System.Management.Automation
// Gets the current WSMan stack version from the registry.
private static Version GetWSManStackVersion()
{
- if (!Platform.HasRegistrySupport())
- {
- return new Version(1, 0);
- }
-
Version version = null;
+#if !LINUX
try
{
using (RegistryKey wsManStackVersionKey = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\WSMAN"))
@@ -133,6 +129,7 @@ namespace System.Management.Automation
catch (FormatException) { }
catch (OverflowException) { }
catch (InvalidCastException) { }
+#endif
return version ?? System.Management.Automation.Remoting.Client.WSManNativeApi.WSMAN_STACK_VERSION;
}
diff --git a/src/System.Management.Automation/engine/Utils.cs b/src/System.Management.Automation/engine/Utils.cs
index ec06e5250..878908be5 100644
--- a/src/System.Management.Automation/engine/Utils.cs
+++ b/src/System.Management.Automation/engine/Utils.cs
@@ -368,14 +368,11 @@ namespace System.Management.Automation
///
internal static bool IsWinPEHost()
{
- if (Platform.HasRegistrySupport())
- {
- return WinIsWinPEHost();
- }
- else
- {
- return false;
- }
+#if LINUX
+ return false;
+#else
+ return WinIsWinPEHost();
+#endif
}
internal static bool WinIsWinPEHost()
diff --git a/src/System.Management.Automation/engine/remoting/commands/remotingcommandutil.cs b/src/System.Management.Automation/engine/remoting/commands/remotingcommandutil.cs
index 2f0fa35d5..c3e9cc006 100644
--- a/src/System.Management.Automation/engine/remoting/commands/remotingcommandutil.cs
+++ b/src/System.Management.Automation/engine/remoting/commands/remotingcommandutil.cs
@@ -96,12 +96,10 @@ namespace Microsoft.PowerShell.Commands
///
internal static void CheckRemotingCmdletPrerequisites()
{
- //If the operating system (ie Linux) does not support the registry, simply return to avoid calls to the Windows registry.
- if (!Platform.HasRegistrySupport())
- {
- return;
- }
-
+#if LINUX
+ // TODO: check that PSRP requirements are installed
+ return;
+#else
bool notSupported = true;
String WSManKeyPath = "Software\\Microsoft\\Windows\\CurrentVersion\\WSMAN\\";
@@ -155,6 +153,7 @@ namespace Microsoft.PowerShell.Commands
throw new InvalidOperationException(
"Windows PowerShell remoting features are not enabled or not supported on this machine.\nThis may be because you do not have the correct version of WS-Management installed or this version of Windows does not support remoting currently.\n For more information, type 'get-help about_remote_requirements'.");
}
+#endif
}
///
diff --git a/src/System.Management.Automation/namespaces/RegistryProvider.cs b/src/System.Management.Automation/namespaces/RegistryProvider.cs
index 1951f59ee..9a168ff7f 100644
--- a/src/System.Management.Automation/namespaces/RegistryProvider.cs
+++ b/src/System.Management.Automation/namespaces/RegistryProvider.cs
@@ -136,11 +136,7 @@ namespace Microsoft.PowerShell.Commands
{
Collection drives = new Collection();
- if (!Platform.HasRegistrySupport())
- {
- return drives;
- }
-
+#if !LINUX
drives.Add(
new PSDriveInfo(
"HKLM",
@@ -156,6 +152,7 @@ namespace Microsoft.PowerShell.Commands
"HKEY_CURRENT_USER",
RegistryProviderStrings.HKCUDriveDescription,
null));
+#endif
return drives;
} // InitializeDefaultDrives
diff --git a/src/System.Management.Automation/namespaces/SafeRegistryHandle.cs b/src/System.Management.Automation/namespaces/SafeRegistryHandle.cs
index 1e817966b..80120a702 100644
--- a/src/System.Management.Automation/namespaces/SafeRegistryHandle.cs
+++ b/src/System.Management.Automation/namespaces/SafeRegistryHandle.cs
@@ -58,13 +58,13 @@ namespace Microsoft.PowerShell.Commands.Internal
override protected bool ReleaseHandle()
{
- if (!Platform.HasRegistrySupport())
- {
- return true;
- }
+#if LINUX
+ return true;
+#else
// Returns a Win32 error code, 0 for success
int r = RegCloseKey(handle);
return r == 0;
+#endif
}
}
}
diff --git a/test/csharp/test_CorePsPlatform.cs b/test/csharp/test_CorePsPlatform.cs
index 44784983f..80d387891 100644
--- a/test/csharp/test_CorePsPlatform.cs
+++ b/test/csharp/test_CorePsPlatform.cs
@@ -15,12 +15,6 @@ namespace PSTests
Assert.True(Platform.IsCore);
}
- [Fact]
- public static void TestHasRegistrySupport()
- {
- Assert.False(Platform.HasRegistrySupport());
- }
-
[Fact]
public static void TestGetUserName()
{