Windows-8 如何编写脚本来更改分辨率?

Windows-8 如何编写脚本来更改分辨率?

我有一台配有高分辨率显示屏(我认为是 2k)的 yoga 2 pro。这有时会导致程序无法正确缩放,但大多数情况下我可以忽略。

但是我也将远程桌面连接到我的工作电脑,它只有 1080p 的显示屏。这让工作变得非常困难,因为远程会话是在 3200x1800 下完成的。所以我每次都通过右键单击桌面 > 更改分辨率 > 选择分辨率 > 点击接受 > 接受弹出窗口来更改分辨率。

有没有可以编写的脚本来自动完成这一操作?这样我就可以轻松地在分辨率之间来回切换。如果还有办法改变字体缩放比例,那就更好了!

我进行了一些搜索并找到了一些 powerscript 命令,但我无法让它们工作......

编辑:在这里找到这个答案,说 powershell 无法做到这一点如何使用 Powershell(或其他)脚本来更改屏幕分辨率?

我想我可以在网上找到一个实用程序。有什么推荐吗?

答案1

以下 Powershell 脚本将分辨率设置为指定值(在我的示例中为 1280 x 1024):--刚刚注意到这是您链接的文章中引用的相同脚本。它有效,我已经在 Win 8.1 Pro 和 Enterprise 上测试过它。

    Function Set-ScreenResolution { 

<# 
    .Synopsis 
        Sets the Screen Resolution of the primary monitor 
    .Description 
        Uses Pinvoke and ChangeDisplaySettings Win32API to make the change 
    .Example 
        Set-ScreenResolution -Width 1024 -Height 768         
    #> 
param ( 
[Parameter(Mandatory=$true, 
           Position = 0)] 
[int] 
$Width, 

[Parameter(Mandatory=$true, 
           Position = 1)] 
[int] 
$Height 
) 

$pinvokeCode = @" 

using System; 
using System.Runtime.InteropServices; 

namespace Resolution 
{ 

    [StructLayout(LayoutKind.Sequential)] 
    public struct DEVMODE1 
    { 
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] 
        public string dmDeviceName; 
        public short dmSpecVersion; 
        public short dmDriverVersion; 
        public short dmSize; 
        public short dmDriverExtra; 
        public int dmFields; 

        public short dmOrientation; 
        public short dmPaperSize; 
        public short dmPaperLength; 
        public short dmPaperWidth; 

        public short dmScale; 
        public short dmCopies; 
        public short dmDefaultSource; 
        public short dmPrintQuality; 
        public short dmColor; 
        public short dmDuplex; 
        public short dmYResolution; 
        public short dmTTOption; 
        public short dmCollate; 
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] 
        public string dmFormName; 
        public short dmLogPixels; 
        public short dmBitsPerPel; 
        public int dmPelsWidth; 
        public int dmPelsHeight; 

        public int dmDisplayFlags; 
        public int dmDisplayFrequency; 

        public int dmICMMethod; 
        public int dmICMIntent; 
        public int dmMediaType; 
        public int dmDitherType; 
        public int dmReserved1; 
        public int dmReserved2; 

        public int dmPanningWidth; 
        public int dmPanningHeight; 
    }; 



    class User_32 
    { 
        [DllImport("user32.dll")] 
        public static extern int EnumDisplaySettings(string deviceName, int modeNum, ref DEVMODE1 devMode); 
        [DllImport("user32.dll")] 
        public static extern int ChangeDisplaySettings(ref DEVMODE1 devMode, int flags); 

        public const int ENUM_CURRENT_SETTINGS = -1; 
        public const int CDS_UPDATEREGISTRY = 0x01; 
        public const int CDS_TEST = 0x02; 
        public const int DISP_CHANGE_SUCCESSFUL = 0; 
        public const int DISP_CHANGE_RESTART = 1; 
        public const int DISP_CHANGE_FAILED = -1; 
    } 



    public class PrmaryScreenResolution 
    { 
        static public string ChangeResolution(int width, int height) 
        { 

            DEVMODE1 dm = GetDevMode1(); 

            if (0 != User_32.EnumDisplaySettings(null, User_32.ENUM_CURRENT_SETTINGS, ref dm)) 
            { 

                dm.dmPelsWidth = width; 
                dm.dmPelsHeight = height; 

                int iRet = User_32.ChangeDisplaySettings(ref dm, User_32.CDS_TEST); 

                if (iRet == User_32.DISP_CHANGE_FAILED) 
                { 
                    return "Unable To Process Your Request. Sorry For This Inconvenience."; 
                } 
                else 
                { 
                    iRet = User_32.ChangeDisplaySettings(ref dm, User_32.CDS_UPDATEREGISTRY); 
                    switch (iRet) 
                    { 
                        case User_32.DISP_CHANGE_SUCCESSFUL: 
                            { 
                                return "Success"; 
                            } 
                        case User_32.DISP_CHANGE_RESTART: 
                            { 
                                return "You Need To Reboot For The Change To Happen.\n If You Feel Any Problem After Rebooting Your Machine\nThen Try To Change Resolution In Safe Mode."; 
                            } 
                        default: 
                            { 
                                return "Failed To Change The Resolution"; 
                            } 
                    } 

                } 


            } 
            else 
            { 
                return "Failed To Change The Resolution."; 
            } 
        } 

        private static DEVMODE1 GetDevMode1() 
        { 
            DEVMODE1 dm = new DEVMODE1(); 
            dm.dmDeviceName = new String(new char[32]); 
            dm.dmFormName = new String(new char[32]); 
            dm.dmSize = (short)Marshal.SizeOf(dm); 
            return dm; 
        } 
    } 
} 

"@ 

Add-Type $pinvokeCode -ErrorAction SilentlyContinue 
[Resolution.PrmaryScreenResolution]::ChangeResolution($width,$height) 
} 

Set-ScreenResolution 1280 1024

相关内容