- # 定义 Windows API 函数
- Add-Type @"
- using System;
- using System.Runtime.InteropServices;
- public class WinAPI {
- [DllImport("user32.dll", SetLastError = true)]
- public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
- [DllImport("user32.dll", SetLastError = true)]
- public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string lpszClass, string lpszWindow);
- [DllImport("user32.dll", SetLastError = true)]
- public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
- public const int LVM_FIRST = 0x1000;
- public const int LVM_SETICONSPACING = LVM_FIRST + 53;
- public const int HWND_BROADCAST = 0xFFFF;
- public const int WM_SETTINGCHANGE = 0x001A;
- }
- "@
- # 设置图标大小
- function Set-IconSize {
- param (
- [int]$iconSize
- )
- # 修改注册表中的图标大小设置
- Set-ItemProperty -Path "HKCU:\Control Panel\Desktop\WindowMetrics" -Name "Shell Icon Size" -Value $iconSize
- # 获取桌面窗口句柄
- $desktopHandle = [WinAPI]::FindWindow("Progman", "Program Manager")
- if ($desktopHandle -eq [IntPtr]::Zero) {
- # 如果未找到 Progman 窗口,尝试查找 WorkerW 窗口
- $desktopHandle = [WinAPI]::FindWindow("WorkerW", $null)
- if ($desktopHandle -eq [IntPtr]::Zero) {
- Write-Error "无法找到桌面窗口句柄!"
- exit
- }
- }
- # 获取桌面 ListView 控件句柄
- $listViewHandle = [IntPtr]::Zero
- $childHandle = [IntPtr]::Zero
- do {
- $childHandle = [WinAPI]::FindWindowEx($desktopHandle, $childHandle, "SysListView32", $null)
- if ($childHandle -ne [IntPtr]::Zero) {
- $listViewHandle = $childHandle
- break
- }
- } while ($childHandle -ne [IntPtr]::Zero)
- if ($listViewHandle -eq [IntPtr]::Zero) {
- Write-Error "无法找到桌面 ListView 控件句柄!"
- exit
- }
- # 设置图标间距(强制刷新布局)
- $iconSpacing = ($iconSize -shl 16) -bor $iconSize
- [WinAPI]::SendMessage($listViewHandle, [WinAPI]::LVM_SETICONSPACING, [IntPtr]::Zero, [IntPtr]$iconSpacing)
- # 发送 WM_SETTINGCHANGE 消息通知资源管理器刷新
- [WinAPI]::SendMessage([WinAPI]::HWND_BROADCAST, [WinAPI]::WM_SETTINGCHANGE, [IntPtr]::Zero, [IntPtr]::Zero)
- Write-Output "桌面图标大小已修改为 $iconSize。"
- }
- # 将图标大小设置为小图标(32x32)
- Set-IconSize -iconSize 32
- # 等待 5 秒
- Start-Sleep -Seconds 5
- # 将图标大小设置为中等图标(48x48)
- 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 控件是纯净系统必有的
谁帮我测试一下? |