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
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,16 @@ class ConsoleHostRawUserInterface : System.Management.Automation.Host.PSHostRawU
// (we may load resources which can take some time)
Task.Run(() =>
{
WindowsIdentity identity = WindowsIdentity.GetCurrent();
WindowsPrincipal principal = new WindowsPrincipal(identity);
var identity = WindowsIdentity.GetCurrent();
var principal = new WindowsPrincipal(identity);
if (principal.IsInRole(WindowsBuiltInRole.Administrator))
{
string prefix = ConsoleHostRawUserInterfaceStrings.WindowTitleElevatedPrefix;

// check using Regex if the window already has Administrator: prefix
// (i.e. from the parent console process)
string titlePattern = ConsoleHostRawUserInterfaceStrings.WindowTitleTemplate;
titlePattern = Regex.Escape(titlePattern)
.Replace(@"\{1}", ".*")
.Replace(@"\{0}", Regex.Escape(prefix));
if (!Regex.IsMatch(this.WindowTitle, titlePattern))
Copy link
Copy Markdown
Member Author

@daxian-dbw daxian-dbw Oct 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to get rid of using Regex at startup, which is not necessary.

// Check if the window already has the "Administrator: " prefix (i.e. from the parent console process).
ReadOnlySpan<char> prefix = ConsoleHostRawUserInterfaceStrings.WindowTitleElevatedPrefix;
ReadOnlySpan<char> windowTitle = WindowTitle;
if (!windowTitle.StartsWith(prefix))
{
this.WindowTitle = StringUtil.Format(ConsoleHostRawUserInterfaceStrings.WindowTitleTemplate,
prefix,
this.WindowTitle);
WindowTitle = string.Concat(prefix, windowTitle);
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,6 @@
<value>Window title cannot be longer than {0} characters.</value>
</data>
<data name="WindowTitleElevatedPrefix" xml:space="preserve">
<value>Administrator</value>
</data>
<data name="WindowTitleTemplate" xml:space="preserve">
<value>{0}: {1}</value>
<value>Administrator: </value>
</data>
</root>
40 changes: 20 additions & 20 deletions src/System.Management.Automation/engine/PSVersionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,20 @@ public static class PSVersionInfo
/// For each later release of PowerShell, this constant needs to
/// be updated to reflect the right version.
/// </remarks>
private static readonly Version s_psV1Version = new Version(1, 0);
private static readonly Version s_psV2Version = new Version(2, 0);
private static readonly Version s_psV3Version = new Version(3, 0);
private static readonly Version s_psV4Version = new Version(4, 0);
private static readonly Version s_psV5Version = new Version(5, 0);
private static readonly Version s_psV51Version = new Version(5, 1, NTVerpVars.PRODUCTBUILD, NTVerpVars.PRODUCTBUILD_QFE);
private static readonly SemanticVersion s_psV6Version = new SemanticVersion(6, 0, 0, preReleaseLabel: null, buildLabel: null);
private static readonly SemanticVersion s_psV61Version = new SemanticVersion(6, 1, 0, preReleaseLabel: null, buildLabel: null);
private static readonly SemanticVersion s_psV62Version = new SemanticVersion(6, 2, 0, preReleaseLabel: null, buildLabel: null);
private static readonly SemanticVersion s_psV7Version = new SemanticVersion(7, 0, 0, preReleaseLabel: null, buildLabel: null);
private static readonly SemanticVersion s_psV71Version = new SemanticVersion(7, 1, 0, preReleaseLabel: null, buildLabel: null);
private static readonly SemanticVersion s_psV72Version = new SemanticVersion(7, 2, 0, preReleaseLabel: null, buildLabel: null);
private static readonly SemanticVersion s_psSemVersion;
private static readonly Version s_psV1Version = new(1, 0);
private static readonly Version s_psV2Version = new(2, 0);
Comment thread
daxian-dbw marked this conversation as resolved.
private static readonly Version s_psV3Version = new(3, 0);
private static readonly Version s_psV4Version = new(4, 0);
private static readonly Version s_psV5Version = new(5, 0);
private static readonly Version s_psV51Version = new(5, 1, NTVerpVars.PRODUCTBUILD, NTVerpVars.PRODUCTBUILD_QFE);
private static readonly Version s_psV6Version = new(6, 0, 0);
Comment thread
daxian-dbw marked this conversation as resolved.
private static readonly Version s_psV61Version = new(6, 1, 0);
private static readonly Version s_psV62Version = new(6, 2, 0);
private static readonly Version s_psV7Version = new(7, 0, 0);
private static readonly Version s_psV71Version = new(7, 1, 0);
private static readonly Version s_psV72Version = new(7, 2, 0);
private static readonly Version s_psVersion;
private static readonly SemanticVersion s_psSemVersion;

/// <summary>
/// A constant to track current PowerShell Edition.
Expand Down Expand Up @@ -108,13 +108,13 @@ static PSVersionInfo()
s_psSemVersion = new SemanticVersion(mainVersion);
Comment thread
daxian-dbw marked this conversation as resolved.
Outdated
s_psVersion = (Version)s_psSemVersion;

s_psVersionTable[PSVersionInfo.PSVersionName] = s_psSemVersion;
s_psVersionTable[PSVersionInfo.PSEditionName] = PSEditionValue;
s_psVersionTable[PSVersionName] = s_psSemVersion;
s_psVersionTable[PSEditionName] = PSEditionValue;
s_psVersionTable[PSGitCommitIdName] = rawGitCommitId;
s_psVersionTable[PSCompatibleVersionsName] = new Version[] { s_psV1Version, s_psV2Version, s_psV3Version, s_psV4Version, s_psV5Version, s_psV51Version, s_psV6Version, s_psV61Version, s_psV62Version, s_psV7Version, s_psV71Version, s_psV72Version, s_psVersion };
s_psVersionTable[PSVersionInfo.SerializationVersionName] = new Version(InternalSerializer.DefaultVersion);
s_psVersionTable[PSVersionInfo.PSRemotingProtocolVersionName] = RemotingConstants.ProtocolVersion;
s_psVersionTable[PSVersionInfo.WSManStackVersionName] = GetWSManStackVersion();
s_psVersionTable[SerializationVersionName] = new Version(InternalSerializer.DefaultVersion);
s_psVersionTable[PSRemotingProtocolVersionName] = RemotingConstants.ProtocolVersion;
s_psVersionTable[WSManStackVersionName] = GetWSManStackVersion();
Comment thread
daxian-dbw marked this conversation as resolved.
Outdated
s_psVersionTable[PSPlatformName] = Environment.OSVersion.Platform.ToString();
s_psVersionTable[PSOSName] = Runtime.InteropServices.RuntimeInformation.OSDescription;
}
Expand Down Expand Up @@ -330,12 +330,12 @@ internal static Version PSV51Version
get { return s_psV51Version; }
}

internal static SemanticVersion PSV6Version
internal static Version PSV6Version
{
get { return s_psV6Version; }
}

internal static SemanticVersion PSV7Version
internal static Version PSV7Version
{
get { return s_psV7Version; }
}
Expand Down