写一个bat脚本,自动执行以下任务: 1. 关闭鼠标“增强指针精度” 2. 设置虚拟内存为当前实际物...

Created on: December 13, 2025

Answered using GPT-5.2 Thinking by Chat01

Question

写一个bat脚本,自动执行以下任务:

  1. 关闭鼠标“增强指针精度”
  2. 设置虚拟内存为当前实际物理内存的1.5倍
  3. 添加电源计划(释放性能、降低延迟),要网友推荐的最新的win11的游戏电源计划
  4. 验证修改是否生效

Question

写一个bat脚本,自动执行以下任务:

  1. 关闭鼠标“增强指针精度”
  2. 设置虚拟内存为当前实际物理内存的1.5倍
  3. 添加电源计划(释放性能、降低延迟),要网友推荐的最新的win11的游戏电源计划
  4. 验证修改是否生效

Thought

Crafting the script for Win11 with admin requirements

I need to write the script for Windows 11 that checks for admin privileges and elevates if needed. First, I’ll use a basic command to check admin access. If not, I'll relaunch the script with elevated permissions. Then I'll disable EPP, adjust Mouse settings, and update virtual memory. Some extra steps might be required for the current session. I'll also notify about the adjustments in acceleration curves, though I'll avoid changing them to be safe.

Setting pagefile and power plan with batch script

I need to disable automatic pagefile management and set a custom pagefile size using PowerShell commands. If the pagefile doesn’t exist, I’ll create one. For the power plan, I’ll use powercfg to duplicate the Ultimate Performance scheme and handle output. To keep things clean in the batch script, I'll write temporary tasks to PowerShell files.

Adjusting power settings with localized support

I'll run powercfg to duplicate the Ultimate Performance power plan and then query the GUID regardless of language. Using PowerShell’s regex, I’ll capture the GUID, then activate it and adjust settings. I'll disable PCIe ASPM and USB selective suspend, applying the changes to the active scheme for simplicity.

Following Microsoft recommendations for device power settings

I'll set USB selective suspend to 0, as per Microsoft's troubleshooting guidance, which corresponds to disabling it. I'll also set the disk idle timeout and processor settings to specific values, then commit these changes with powercfg /setactive. Finally, I'll verify by querying the registry to ensure everything aligns with expectations.

Providing script to set power plan and pagefile settings

I’ll create a batch script that checks pagefile settings and power plans. For pagefiles, I'll display settings using PowerShell, and for the power plan, I’ll use powercfg to show the active scheme. I'll provide instructions, mention the need for rebooting, and include a caution for laptops about power usage. The script sets the pagefile on the system drive and supports self-elevation for admin rights. I'll add helpful citations and a minimal explanation in the response.

Creating a batch script for pagefile and power plan setup

I'll create a batch script with several tasks. First, it will disable enhanced pointer precision, then set the pagefile to 1.5x the system RAM. After that, the script will try to add and activate the Ultimate Performance power plan, using PowerShell commands. If it fails to create, it will attempt to find an existing one. It will also handle user permissions and reboot prompts.

Thought for 3m 42s

Answer

下面是一份 Windows 11 用的一键优化 .bat(会自动提权管理员),按你要求做:

  • 关闭鼠标“增强指针精度”(指针加速)
  • 将虚拟内存(pagefile)设置为 实际物理内存的 1.5 倍(初始=最大,单位 MB)
  • 添加并启用 “Ultimate Performance / 卓越性能”(这是 Windows 自带隐藏电源计划,很多 Win11 游戏优化教程/网友推荐用它来减少电源管理带来的微延迟)(How-To Geek)
  • 输出验证信息(注册表/WMI/电源计划查询)

注意:虚拟内存设置在“下次开机”创建/调整生效(WMI 也说明页文件参数在系统启动时用于创建)(Microsoft Learn)


一键脚本(保存为 Win11_Gaming_Tweak.bat,右键“以管理员身份运行”)

bat
@echo off setlocal EnableExtensions EnableDelayedExpansion :: ========================= :: Self-elevate to Admin :: ========================= net session >nul 2>&1 if %errorlevel% neq 0 ( echo [*] 需要管理员权限,正在自动提权... powershell -NoProfile -ExecutionPolicy Bypass -Command "Start-Process -FilePath '%~f0' -Verb RunAs" exit /b ) echo ================================================== echo Win11 Gaming Tweak (Mouse + Pagefile + Power Plan) echo ================================================== echo. :: ========================= :: 1) Disable Enhance Pointer Precision :: ========================= echo [1/4] 关闭鼠标“增强指针精度”(指针加速)... reg add "HKCU\Control Panel\Mouse" /v MouseSpeed /t REG_SZ /d 0 /f >nul reg add "HKCU\Control Panel\Mouse" /v MouseThreshold1 /t REG_SZ /d 0 /f >nul reg add "HKCU\Control Panel\Mouse" /v MouseThreshold2 /t REG_SZ /d 0 /f >nul :: 刷新用户参数(不保证所有机器立即生效,但无害) rundll32.exe user32.dll,UpdatePerUserSystemParameters 1,True >nul 2>&1 echo OK :: 参考:EPP 对应的注册表就是这三个值([tenforums.com](https://www.tenforums.com/tutorials/101691-turn-off-enhance-pointer-precision-windows.html?utm_source=chatgpt.com)) echo. :: ========================= :: 2) Set Pagefile = 1.5x RAM :: ========================= echo [2/4] 设置虚拟内存(pagefile) = 物理内存 * 1.5 (初始=最大)... set "TMPPS1=%temp%\_set_pagefile_15x.ps1" > "%TMPPS1%" ( echo $ErrorActionPreference = 'Stop' echo $ramBytes = (Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory echo $sizeMB = [math]::Round(($ramBytes/1MB) * 1.5) echo $drive = $env:SystemDrive echo $name = "$drive\pagefile.sys" echo echo # Disable auto management echo $cs = Get-CimInstance Win32_ComputerSystem echo $cs.AutomaticManagedPagefile = $false echo Set-CimInstance -InputObject $cs ^| Out-Null echo echo # Create/Update pagefile setting echo $filterName = $name -replace '\\','\\\\' echo $pfs = Get-CimInstance Win32_PageFileSetting -Filter ("Name='" + $filterName + "'") -ErrorAction SilentlyContinue echo if (-not $pfs) ^{ echo New-CimInstance -ClassName Win32_PageFileSetting -Property @{Name=$name; InitialSize=$sizeMB; MaximumSize=$sizeMB} ^| Out-Null echo ^} else ^{ echo $pfs.InitialSize = $sizeMB echo $pfs.MaximumSize = $sizeMB echo Set-CimInstance -InputObject $pfs ^| Out-Null echo ^} echo echo "PAGEFILE_MB=$sizeMB" ) for /f "tokens=2 delims==" %%A in ('powershell -NoProfile -ExecutionPolicy Bypass -File "%TMPPS1%"') do set "PFMB=%%A" del /f /q "%TMPPS1%" >nul 2>&1 if defined PFMB ( echo OK 设为 %PFMB% MB(提示:通常需要重启后完全生效) ) else ( echo [!] 设置失败:未能计算/写入 pagefile ) echo. :: ========================= :: 3) Add + activate "Ultimate Performance" power plan and tweak :: ========================= echo [3/4] 添加并启用 Win11 游戏电源计划(Ultimate Performance/卓越性能)... :: 通过 PowerShell 抓取 powercfg 输出中的 GUID(避免中文系统解析失败) for /f %%G in ('powershell -NoProfile -Command ^ "$o = powercfg -duplicatescheme e9a42b02-d5df-448d-aa00-03f14749eb61; ^ ($o | Select-String -Pattern ''[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}'' ).Matches.Value | Select-Object -First 1"') do set "UPGUID=%%G" if not defined UPGUID ( echo [!] 无法创建计划(可能已存在/系统限制),尝试继续用当前计划做低延迟参数... ) else ( powercfg -setactive %UPGUID% >nul 2>&1 echo OK 已启用方案 GUID=%UPGUID% ) :: 低延迟/性能向常见调整(AC=插电时) :: PCIe Link State Power Management = Off (0)([Microsoft Learn](https://learn.microsoft.com/en-us/answers/questions/1332551/how-to-modify-link-state-power-management-to-be-mo?utm_source=chatgpt.com)) powercfg /setacvalueindex SCHEME_CURRENT 501a4d13-42af-4429-9fd1-a8218c268e20 ee12f906-d277-404b-b6da-e5fa1a576df5 0 >nul 2>&1 :: USB Selective Suspend = Disabled (0)(MS 文档示例用 0 来关闭该项)([Microsoft Learn](https://learn.microsoft.com/en-us/troubleshoot/microsoftteams/teams-rooms-and-devices/usb-selective-suspend-status-unhealthy?utm_source=chatgpt.com)) powercfg /setacvalueindex SCHEME_CURRENT 2a737441-1930-4402-8d77-b2bebba308a3 48e6b7a6-50f5-4782-a5d4-53bb8f07e226 0 >nul 2>&1 :: Hard disk idle = Never (0) powercfg /setacvalueindex SCHEME_CURRENT 0012ee47-9041-4b5d-9b77-535fba8b1442 6738e2c4-e8a5-4a42-b16a-e040e769756e 0 >nul 2>&1 :: CPU min/max = 100% powercfg /setacvalueindex SCHEME_CURRENT 54533251-82be-4824-96c1-47b60b740d00 893dee8e-2bef-41e0-89c6-b55d0929964c 100 >nul 2>&1 powercfg /setacvalueindex SCHEME_CURRENT 54533251-82be-4824-96c1-47b60b740d00 bc5038f7-23e0-4960-96da-33abaf5935ec 100 >nul 2>&1 powercfg -setactive SCHEME_CURRENT >nul 2>&1 echo OK 已写入低延迟参数(插电) echo. :: ========================= :: 4) Verify :: ========================= echo [4/4] 验证修改是否生效(输出查询结果)... echo. echo ---- Mouse (EPP) Registry ---- reg query "HKCU\Control Panel\Mouse" /v MouseSpeed reg query "HKCU\Control Panel\Mouse" /v MouseThreshold1 reg query "HKCU\Control Panel\Mouse" /v MouseThreshold2 echo. echo ---- Pagefile (WMI) ---- powershell -NoProfile -Command "Get-CimInstance Win32_ComputerSystem | Select-Object AutomaticManagedPagefile | Format-List" powershell -NoProfile -Command "Get-CimInstance Win32_PageFileSetting | Select-Object Name,InitialSize,MaximumSize | Format-Table -AutoSize" echo. echo ---- Active Power Plan ---- powercfg /getactivescheme echo. echo ---- Power Tweaks (AC) Quick Query ---- echo [PCIe ASPM] powercfg /query SCHEME_CURRENT 501a4d13-42af-4429-9fd1-a8218c268e20 ee12f906-d277-404b-b6da-e5fa1a576df5 echo [USB Selective Suspend] powercfg /query SCHEME_CURRENT 2a737441-1930-4402-8d77-b2bebba308a3 48e6b7a6-50f5-4782-a5d4-53bb8f07e226 echo. echo ========================= echo 完成。建议重启一次,让 pagefile 设置完全生效。 echo ========================= pause

说明(很短)

  • “增强指针精度”本质就是改 HKCU\Control Panel\MouseMouseSpeed/MouseThreshold1/MouseThreshold2 为 0。(tenforums.com)
  • 电源计划用的是 Windows 自带隐藏的 Ultimate Performance,常见启用方式就是 powercfg -duplicatescheme e9a42b02-d5df-448d-aa00-03f14749eb61。(Pureinfotech)
  • Ultimate Performance 被许多优化文章解释为减少电源管理“微延迟”,适合追求响应/性能(但更耗电更热)。(How-To Geek)

如果你希望脚本把“只在插电时启用这些激进设置、用电池时自动回到平衡”,我也可以给你加上 DC(电池)分支。

Share this Q&A