|
|
发表于 2025-5-16 21:06:52
|
显示全部楼层
方法2:使用 PowerShell 调用 Windows API(更底层控制)
如果 DisplaySwitch.exe 不适用,可以使用以下脚本直接修改显示模式:
powershell- Add-Type -TypeDefinition @'
- using System;
- using System.Runtime.InteropServices;
- public class DisplaySettings {
- [DllImport("user32.dll")]
- public static extern int SetDisplayConfig(
- uint numPathArrayElements,
- IntPtr pathArray,
- uint numModeInfoArrayElements,
- IntPtr modeInfoArray,
- uint flags
- );
- public const uint SDC_TOPOLOGY_INTERNAL = 0x00000001; // 仅主显示器
- public const uint SDC_TOPOLOGY_CLONE = 0x00000002; // 复制模式
- public const uint SDC_TOPOLOGY_EXTEND = 0x00000004; // 扩展模式
- public const uint SDC_APPLY = 0x00000080; // 应用更改
- }
- '@
- # 设置为仅主显示器
- [DisplaySettings]::SetDisplayConfig(0, IntPtr.Zero, 0, IntPtr.Zero,
- [DisplaySettings]::SDC_TOPOLOGY_INTERNAL -bor [DisplaySettings]::SDC_APPLY)
复制代码 deepseek回答,未测试 |
|