windows – Powershell Set Lid关闭动作
发布时间:2020-12-13 20:39:58 所属栏目:Windows 来源:网络整理
导读:我希望自动设置Windows 7在我的工作笔记本电脑上关闭盖子时所采取的操作,因为每次登录时都会通过GPO重置. 我知道我可以在批处理脚本中使用powercfg命令来实现这个目的: powercfg -setacvalueindex 5ca83367-6e45-459f-a27b-476b1d01c936 0powercfg -setdcva
我希望自动设置Windows 7在我的工作笔记本电脑上关闭盖子时所采取的操作,因为每次登录时都会通过GPO重置.
我知道我可以在批处理脚本中使用powercfg命令来实现这个目的: powercfg -setacvalueindex 5ca83367-6e45-459f-a27b-476b1d01c936 0 powercfg -setdcvalueindex 5ca83367-6e45-459f-a27b-476b1d01c936 0 然而,这是尝试学习一些PowerShell的一个很好的借口.我的第一次尝试需要10秒以上才能运行. 在运行时和运行方面,我如何改进以下内容?在清洁代码方面.接近下面的惯用PowerShell方法是什么? $DO_NOTHING = 0 $activePowerPlan = Get-WmiObject -Namespace "rootcimv2power" Win32_PowerPlan | where {$_.IsActive} $rawPowerPlanID = $activePowerPlan | select -Property InstanceID $rawPowerPlanID -match '({.*})}' $powerPlanID = $matches[1] # The .GetRelated() method is an inefficient approach,i'm looking for a needle and this haystack is too big. Can i go directly to the object instead of searching? $lidCloseActionOnACPower = $activePowerPlan.GetRelated("win32_powersettingdataindex") | where {$_.InstanceID -eq "Microsoft:PowerSettingDataIndex$powerPlanIDAC{5ca83367-6e45-459f-a27b-476b1d01c936}"} $lidCloseActionOnBattery = $activePowerPlan.GetRelated("win32_powersettingdataindex") | where {$_.InstanceID -eq "Microsoft:PowerSettingDataIndex$powerPlanIDDC{5ca83367-6e45-459f-a27b-476b1d01c936}"} $lidCloseActionOnACPower | select -Property SettingIndexValue $lidCloseActionOnACPower.SettingIndexValue = $DO_NOTHING $lidCloseActionOnACPower.put() $lidCloseActionOnBattery | select -Property SettingIndexValue $lidCloseActionOnBattery.SettingIndexValue = $DO_NOTHING $lidCloseActionOnBattery.put()
试试WMI加速器:
$class = ([wmi] 'rootcimv2power:Win32_PowerSettingDataIndex.InstanceID="Microsoft:PowerSettingDataIndex{8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c}DC{5ca83367-6e45-459f-a27b-476b1d01c936}"') $class.SettingIndexValue = 0 $class.Put() (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- windows-xp – 如何在CMD.exe中创建符号(硬链接)
- 在发布时,更改Windows通用应用程序Windows Phone 8.1应用程
- powershell – 如何在Add-AzureAccount中使用Microsoft(非组
- windows-server-2003 – 更改Microsoft Windows DNS服务器上
- 在Wix中创建自定义操作以用于静默安装
- libusb_open在Windows 7上返回’LIBUSB_ERROR_NOT_SUPPORTE
- active-directory – 如何在Windows Server 2008 R2 CA颁发
- windows-7 – 如何在Windows 7中的单个界面上禁用防火墙?
- 防火墙 – Skype在一个企业 – 您的看法是什么?
- windows-server-2003 – 我忘记了W2K3管理员密码.是否可以重
推荐文章
站长推荐
- windows-7 – 程序文件和ProgramData之间的区别?
- winapi – Win32 rsync端口的技术障碍
- windows-server-2012-r2 – Server 2012无法找到
- PHP Windows7+IIS7+PHP+MySQL安装与配置教程
- windows-server-2008 – 高可用性虚拟机
- 如何使用PowerShell以编程方式更改Windows Shell
- windows – WinAPI Unicode和ANSI函数
- 确定用户登录Windows的时间
- windows-server-2003 – 在AD中委派帐户解锁权限
- iis – 防火墙阻止Windows 2008 R2上的FTP服务器
热点阅读