auto arrange icons script via task scheduler

rae 1 Reputation point
2024-01-09T19:35:38.5433333+00:00

Jaspreet Singh suggested I post here,

auto arrange icons script via task scheduler, otherwise a powershell script to reset icons via auto arrange, medium size on shared desktops when logging in?

Looking foe a solution.

thanks

Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Azar 29,520 Reputation points MVP Volunteer Moderator
    2024-01-09T19:54:03.27+00:00

    Hi rae
    You can do this using PowerShell script that resets desktop icons to the "Auto Arrange" and "Medium Icons" settings. This script can be scheduled to run at user logon through Task Scheduler.

    Create a new PowerShell script like the one below

     
    # ArrangeIcons.ps1
    
    # Set the registry values for Auto Arrange and Medium Icons
    Set-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\Shell\Bags\1\Desktop' -Name 'LogicalViewMode' -Value 1
    Set-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\Shell\Bags\1\Desktop' -Name 'IconSize' -Value 0
    
    # Send a broadcast message to refresh the desktop
    $signature = @"
        [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
        public static extern int SendMessageTimeout(
            IntPtr hWnd,
            uint Msg,
            UIntPtr wParam,
            UIntPtr lParam,
            SendMessageTimeoutFlags fuFlags,
            uint uTimeout,
            out UIntPtr lpdwResult
        );
    
        [Flags]
        public enum SendMessageTimeoutFlags : uint {
            SMTO_NORMAL = 0x0,
            SMTO_BLOCK = 0x1,
            SMTO_ABORTIFHUNG = 0x2,
            SMTO_NOTIMEOUTIFNOTHUNG = 0x8
        }
    
        public const int HWND_BROADCAST = 0xFFFF;
        public const int WM_SETTINGCHANGE = 0x001A;
    "@
    
    Add-Type -MemberDefinition $signature -Namespace NativeMethods -Name User32
    [NativeMethods.User32]::SendMessageTimeout([IntPtr]::Zero, [NativeMethods.WM_SETTINGCHANGE], [UIntPtr]::Zero, [UIntPtr]::Zero, [NativeMethods.SendMessageTimeoutFlags]::SMTO_NORMAL, 1000, [IntPtr]::Zero) | Out-Null
    Save the script.
    
    
    

    save the script and now create a task Scheduler task to run this script at user logon.

    If this heps kindly accept the answer thanks much.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.