admin管理员组文章数量:1619183
有时夜晚将亮度调到最暗,早上想调回来时太暗又看不到,想写一个脚本调。参考 [1,2],可用 powershell 命令实现。顺便记录 powershell 脚本参数写法。
Code
# brightness.ps1
# 命令行参数 `b`,[0, 100],默认 50
param ($b = 50)
# echo $b
# 改亮度
(Get-WmiObject -Namespace root/WMI -Class WmiMonitorBrightnessMethods).WmiSetBrightness(1,$b)
powershell 脚本后缀是 .ps1
,存为 brightness.ps1。接受命令行参数的写法参考 [3],设默认值参考 [4]。运行:
.\brightness.ps1
# 或指定亮度 [0, 100]
.\brightness.ps1 -b 90
不过 powershell 默认禁止运行脚本,参考 [5,6],可以:
- 提前在任一 powershell 运行
Set-ExecutionPolicy -Scope CurrentUser Bypass
(对当前用户)赋权。会记在注册表,今后都能运行,可用Get-ExecutionPolicy -Scope CurrentUser
验证; 或用;(无效)unblock-file brightness.ps1
[7,8]- 或在当前 powershell(对此 shell)赋权:
Set-ExecutionPolicy -Scope Process Bypass
;(有点麻烦) - 或用
powershell -ExecutionPolicy Bypass
另起一个赋权的子 shell。
Run in cmd
powershell 脚本只能在 powershell 入面直接用 .\<script>.ps1
或 <path>\<script>.ps1
执行,且要放 bypass 权才方便。
如果不想放权,参考 [9],考虑写个 .bat 文件在 cmd 套娃运行 powershell 脚本,用到 powershell
命令。
@REM bright.bat
@echo off
@REM 命令行参数
if (%1) == () (
set b=50
) else (
set b=%1
)
@REM echo %b%
@REM 执行 powershell 脚本,临时放权
powershell -executionpolicy bypass -File brightness.ps1 %b%
执行 bright.bat
或 bright.bat <亮度>
即可,放在 %USERPROFILE%/ 下(cmd 启动路径)即可 Ctrl + R 呼出 cmd 后盲敲。
References
- 7 ways to adjust the screen brightness in Windows 10
- Windows 11 Change Display Brightness with 9 methods
- about_Scripts
- about_Parameters_Default_Values
- about_Execution_Policies
- Set-ExecutionPolicy
- about_Signing
- Unblock-File
- How to run a PowerShell script
本文标签: 亮度Windowspowershell
版权声明:本文标题:windows用powershell调亮度 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dianzi/1728774483a1172332.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论