Remove pinned Edge icon from taskbar

stevefpc

New Member
Messages
23
Reaction score
0
Hello, has there been an update to remove Edge from taskbar?

This .ps1 file removes MS Store but Edge is still pinned in taskbar.

Thank you


Code:
$UnpinnedList = @('Edge', 'Microsoft Store')

# https://github.com/Disassembler0/Win10-Initial-Setup-Script/issues/8#issue-227159084
#
$GetString = @'
    [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
    public static extern IntPtr GetModuleHandle(string lpModuleName);

    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    internal static extern int LoadString(IntPtr hInstance, uint uID, StringBuilder lpBuffer, int nBufferMax);

    public static string GetString(uint strId) {
        IntPtr intPtr = GetModuleHandle("shell32.dll");
        StringBuilder sb = new StringBuilder(255);
        LoadString(intPtr, strId, sb, sb.Capacity);
        return sb.ToString();
    }
'@

$string = Add-Type $GetString -PassThru -Name GetStr -Using System.Text
$UnpinFromTaskbar = $string[0]::GetString(5387)

foreach ($App in $UnpinnedList) {
    ((New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').Items() | ?{ $_.Name -match $App }).Verbs() | `
        ?{ $_.Name -eq $UnpinFromTaskbar } | %{ $_.DoIt(); $exec = $true }
 
Works for me on W11 24H2. Of course, you have to run this from Post-Setup (After logon), because (Before logon) runs as SYSTEM and not as the Primary User.
 
I tested the script, it works fine but what you're experiencing is known as a race condition.

NTLite creates a RunOnce task to run the PS script, but the desktop is still provisioning the Taskbar while the script has already started its work. The last process running wins, and you don't get everything unpinned. When a scheduled task actually runs is subject to random delays, depending on how busy Windows is at the time.

The workaround is to add a short delay before the script begins its cleanup. I also made the script hide itself so there's not an ugly PS window floating in the background. You may have to adjust the "Start-Sleep" line to increase or decrease the delay.

Code:
$UnpinnedList = @('Edge', 'Microsoft Store')

Add-Type -MemberDefinition @'
    [DllImport("user32.dll")]
    public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
'@ -Namespace Win32 -Name Functions

$null = [Win32.Functions]::ShowWindow(([System.Diagnostics.Process]::GetCurrentProcess() | Get-Process).MainWindowHandle, 0)

# https://github.com/Disassembler0/Win10-Initial-Setup-Script/issues/8#issue-227159084
#
$GetString = @'
    [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
    public static extern IntPtr GetModuleHandle(string lpModuleName);

    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    internal static extern int LoadString(IntPtr hInstance, uint uID, StringBuilder lpBuffer, int nBufferMax);

    public static string GetString(uint strId) {
        IntPtr intPtr = GetModuleHandle("shell32.dll");
        StringBuilder sb = new StringBuilder(255);
        LoadString(intPtr, strId, sb, sb.Capacity);
        return sb.ToString();
    }
'@

$string = Add-Type $GetString -PassThru -Name GetStr -Using System.Text
$UnpinFromTaskbar = $string[0]::GetString(5387)

Start-Sleep 6

foreach ($App in $UnpinnedList) {
    ((New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').Items() | ?{ $_.Name -match $App }).Verbs() | `
        ?{ $_.Name -eq $UnpinFromTaskbar } | %{ $_.DoIt(); $exec = $true }
}
 
Back
Top