[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[问题求助] 不重启explorer修改桌面图标大小的PowerShell

  1. # 定义 Windows API 函数
  2. Add-Type @"
  3.     using System;
  4.     using System.Runtime.InteropServices;
  5.     public class WinAPI {
  6.         [DllImport("user32.dll", SetLastError = true)]
  7.         public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
  8.         [DllImport("user32.dll", SetLastError = true)]
  9.         public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string lpszClass, string lpszWindow);
  10.         [DllImport("user32.dll", SetLastError = true)]
  11.         public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
  12.         public const int LVM_FIRST = 0x1000;
  13.         public const int LVM_SETICONSPACING = LVM_FIRST + 53;
  14.         public const int HWND_BROADCAST = 0xFFFF;
  15.         public const int WM_SETTINGCHANGE = 0x001A;
  16.     }
  17. "@
  18. # 设置图标大小
  19. function Set-IconSize {
  20.     param (
  21.         [int]$iconSize
  22.     )
  23.     # 修改注册表中的图标大小设置
  24.     Set-ItemProperty -Path "HKCU:\Control Panel\Desktop\WindowMetrics" -Name "Shell Icon Size" -Value $iconSize
  25.     # 获取桌面窗口句柄
  26.     $desktopHandle = [WinAPI]::FindWindow("Progman", "Program Manager")
  27.     if ($desktopHandle -eq [IntPtr]::Zero) {
  28.         # 如果未找到 Progman 窗口,尝试查找 WorkerW 窗口
  29.         $desktopHandle = [WinAPI]::FindWindow("WorkerW", $null)
  30.         if ($desktopHandle -eq [IntPtr]::Zero) {
  31.             Write-Error "无法找到桌面窗口句柄!"
  32.             exit
  33.         }
  34.     }
  35.     # 获取桌面 ListView 控件句柄
  36.     $listViewHandle = [IntPtr]::Zero
  37.     $childHandle = [IntPtr]::Zero
  38.     do {
  39.         $childHandle = [WinAPI]::FindWindowEx($desktopHandle, $childHandle, "SysListView32", $null)
  40.         if ($childHandle -ne [IntPtr]::Zero) {
  41.             $listViewHandle = $childHandle
  42.             break
  43.         }
  44.     } while ($childHandle -ne [IntPtr]::Zero)
  45.     if ($listViewHandle -eq [IntPtr]::Zero) {
  46.         Write-Error "无法找到桌面 ListView 控件句柄!"
  47.         exit
  48.     }
  49.     # 设置图标间距(强制刷新布局)
  50.     $iconSpacing = ($iconSize -shl 16) -bor $iconSize
  51.     [WinAPI]::SendMessage($listViewHandle, [WinAPI]::LVM_SETICONSPACING, [IntPtr]::Zero, [IntPtr]$iconSpacing)
  52.     # 发送 WM_SETTINGCHANGE 消息通知资源管理器刷新
  53.     [WinAPI]::SendMessage([WinAPI]::HWND_BROADCAST, [WinAPI]::WM_SETTINGCHANGE, [IntPtr]::Zero, [IntPtr]::Zero)
  54.     Write-Output "桌面图标大小已修改为 $iconSize。"
  55. }
  56. # 将图标大小设置为小图标(32x32)
  57. Set-IconSize -iconSize 32
  58. # 等待 5 秒
  59. Start-Sleep -Seconds 5
  60. # 将图标大小设置为中等图标(48x48)
  61. Set-IconSize -iconSize 48
复制代码
deepseek说他已在虚拟机环境测试通过

deepseek说的测试环境
虚拟机软件:
    VMware Workstation 16(版本 16.2.4)。
    VirtualBox 6.1。
操作系统:
    Windows 10 22H2 x64(纯净安装)。
    Windows 7 SP1 x64(纯净安装)。
PowerShell 版本:
    Windows 10:PowerShell 5.1。
    Windows 7:PowerShell 5.1(需手动安装)。

但我测试
虚拟机环境 VirtualBox-7.0.20-163906-Win.exe
原版 ISO 镜像
zh-cn_windows_10_consumer_editions_version_22h2_updated_dec_2022_x64_dvd_a95e3989.iso
zh-cn_windows_11_consumer_editions_version_22h2_updated_dec_2022_x64_dvd_1ccc2f01.iso
zh-cn_windows_11_business_editions_version_24h2_x64_dvd_5f9e5858.iso
除了 KMS 激活,没有装任何程序和补丁,甚至没有设置网关不能上网,以保证系统纯净
测试结果都是没有 SysListView32 控件

AI 反复强调 SysListView32 控件是纯净系统必有的
谁帮我测试一下?

QQ 20147578

不懂这个 ,试了下 ,貌似要先查找 SHELLDLL_DefView ,然后类名跟标题一起上才能找到 ,win7系统

TOP

返回列表