[release/v7.6.6] Add support for new WLDP setting `EnableFileOnlyEntry` by SeeminglyScience · Pull Request #27922 · PowerShell/PowerShell · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 44 additions & 41 deletions src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,6 @@ internal static int Start(
// improve startup performance.
}

uint exitCode = ExitCodeSuccess;

Thread.CurrentThread.Name = "ConsoleHost main thread";

try
Expand All @@ -192,7 +190,7 @@ internal static int Start(
// or start up the engine and retrieve the information via $psversiontable.GitCommitId
// but this returns the semantic version and avoids executing a script
s_theConsoleHost.UI.WriteLine($"PowerShell {PSVersionInfo.GitCommitId}");
return 0;
return ExitCodeSuccess;
}

// Servermode parameter validation check.
Expand Down Expand Up @@ -223,6 +221,14 @@ internal static int Start(
return ExitCodeBadCommandLineParameter;
}

if (serverModeCount is 1 && CommandLineParameterParser.IsFileOnlyEntryEnabled)
{
// User facing error message should already be written by the parser,
// so just trace and exit.
s_tracer.TraceError("Server mode cannot be specified when FileOnlyEntry policy is in place.");
return ExitCodeBadCommandLineParameter;
}

#if !UNIX
TaskbarJumpList.CreateRunAsAdministratorJumpList();
#endif
Expand All @@ -237,9 +243,10 @@ internal static int Start(
configurationName: null,
configurationFile: s_cpp.ConfigurationFile,
combineErrOutStream: false);
exitCode = 0;
return ExitCodeSuccess;
}
else if (s_cpp.SSHServerMode)

if (s_cpp.SSHServerMode)
{
ApplicationInsightsTelemetry.SendPSCoreStartupTelemetry("SSHServer", s_cpp.ParametersUsedAsDouble);
ProfileOptimization.StartProfile("StartupProfileData-SSHServerMode");
Expand All @@ -249,18 +256,20 @@ internal static int Start(
configurationName: null,
configurationFile: s_cpp.ConfigurationFile,
combineErrOutStream: true);
exitCode = 0;
return ExitCodeSuccess;
}
else if (s_cpp.NamedPipeServerMode)

if (s_cpp.NamedPipeServerMode)
{
ApplicationInsightsTelemetry.SendPSCoreStartupTelemetry("NamedPipe", s_cpp.ParametersUsedAsDouble);
ProfileOptimization.StartProfile("StartupProfileData-NamedPipeServerMode");
RemoteSessionNamedPipeServer.RunServerMode(
configurationName: s_cpp.ConfigurationName);
exitCode = 0;
return ExitCodeSuccess;
}
#if !UNIX
else if (s_cpp.V2SocketServerMode)

if (s_cpp.V2SocketServerMode)
{
if (s_cpp.Token == null)
{
Expand All @@ -284,50 +293,49 @@ internal static int Start(
token: s_cpp.Token,
tokenCreationTime: s_cpp.UTCTimestamp.Value);

exitCode = 0;
return ExitCodeSuccess;
}
#endif
else if (s_cpp.SocketServerMode)

if (s_cpp.SocketServerMode)
{
ApplicationInsightsTelemetry.SendPSCoreStartupTelemetry("SocketServerMode", s_cpp.ParametersUsedAsDouble);
ProfileOptimization.StartProfile("StartupProfileData-SocketServerMode");
HyperVSocketMediator.Run(
initialCommand: s_cpp.InitialCommand,
configurationName: s_cpp.ConfigurationName);
exitCode = 0;
return ExitCodeSuccess;
}
else

// Run PowerShell in normal console mode.
if (hostException != null)
{
// Run PowerShell in normal console mode.
if (hostException != null)
{
// Unable to create console host.
throw hostException;
}
// Unable to create console host.
throw hostException;
}

if (LoadPSReadline())
{
ProfileOptimization.StartProfile("StartupProfileData-Interactive");
if (LoadPSReadline())
{
ProfileOptimization.StartProfile("StartupProfileData-Interactive");

if (UpdatesNotification.CanNotifyUpdates)
{
// Start a task in the background to check for the update release.
_ = UpdatesNotification.CheckForUpdates();
}
}
else
if (UpdatesNotification.CanNotifyUpdates)
{
ProfileOptimization.StartProfile("StartupProfileData-NonInteractive");
// Start a task in the background to check for the update release.
_ = UpdatesNotification.CheckForUpdates();
}
}
else
{
ProfileOptimization.StartProfile("StartupProfileData-NonInteractive");
}

s_theConsoleHost.BindBreakHandler();
IsStdOutputRedirected = Console.IsOutputRedirected;
s_theConsoleHost.BindBreakHandler();
IsStdOutputRedirected = Console.IsOutputRedirected;

// Send startup telemetry for ConsoleHost startup
ApplicationInsightsTelemetry.SendPSCoreStartupTelemetry("Normal", s_cpp.ParametersUsedAsDouble);
// Send startup telemetry for ConsoleHost startup
ApplicationInsightsTelemetry.SendPSCoreStartupTelemetry("Normal", s_cpp.ParametersUsedAsDouble);

exitCode = s_theConsoleHost.Run(s_cpp, false);
}
return unchecked((int)s_theConsoleHost.Run(s_cpp, false));
}
finally
{
Expand All @@ -349,11 +357,6 @@ internal static int Start(
}
#pragma warning restore IDE0031
}

unchecked
{
return (int)exitCode;
}
}

internal static void ParseCommandLine(string[] args)
Expand Down
Loading
Loading