Win10如何禁用屏幕自动旋转(以编程方式或批处理命令)

Win10 How to disable screen autorotation (programmaticaly or in a batch command)

我正在使用 C++/CLI 编写 Windows 10 应用程序。该应用程序将 运行 在便携式计算机上运行(运行 是标准的 Win10 SO,而不是平板电脑版本)。

这台便携式计算机具有自动旋转功能,但我需要让我的应用程序仅处于纵向配置。

我想在应用程序出现时禁用屏幕自动旋转。是否有 C++/CLI 命令、C# 命令或批处理命令,我可以通过编程方式执行(批处理将从我的应用程序调用)?

使用regini.exe,参数文件指定要设置的键:

AutorotateOff.reg:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AutoRotation Enable = REG_DWORD 0DWORD

要在具有提升权限的命令行上发出的命令: <code>c:\>regini AutorotateOff.reg

已经有一段时间了,但这应该可以完成工作:

RegistryKey regKey = Registry.LocalMachine.OpenSubKey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AutoRotation", true);

if(regKey != null)
{
   regKey.SetValue("Enable", "0", RegistryValueKind.DWord);
   regKey.Close();
}