![使用脚本或注册表设置将 Windows XP 电源按钮操作设置为“不执行任何操作”](https://linux22.com/image/1285763/%E4%BD%BF%E7%94%A8%E8%84%9A%E6%9C%AC%E6%88%96%E6%B3%A8%E5%86%8C%E8%A1%A8%E8%AE%BE%E7%BD%AE%E5%B0%86%20Windows%20XP%20%E7%94%B5%E6%BA%90%E6%8C%89%E9%92%AE%E6%93%8D%E4%BD%9C%E8%AE%BE%E7%BD%AE%E4%B8%BA%E2%80%9C%E4%B8%8D%E6%89%A7%E8%A1%8C%E4%BB%BB%E4%BD%95%E6%93%8D%E4%BD%9C%E2%80%9D.png)
如何使用注册表项或脚本将 Windows XP 中的“当我按下计算机上的电源按钮时:”选项设置为“不执行任何操作”?
我发现这个例子在搜索中,但是它应该是睡眠按钮,而且它似乎不起作用。
我找到了这些键,但我不知道正确的值应该是什么,因为它是 REG_BINARY
HKLM\SYSTEM\ControlSet001\Control\Session Manager\Power\AcPolicy
HKLM\SYSTEM\ControlSet001\Control\Session Manager\Power\DcPolicy
HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Power\AcPolicy
HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Power\DcPolicy
答案1
不知道您是否仍在寻找解决方案。我需要将电源按钮设置从默认的“关机”更改为“不执行任何操作”,所以我编写了这个 vbscript。
'***************************************************************************************
' File: pwrDoNothing.vbs
' Author: Joe Rawlins
' Purpose: Set system Power Button to 'Do nothing'
'
'
' Notes: Requires button to be held for 5 seconds to initiate shutdown
'
'
'
'
' Last Modified: 06/25/2010 jtr Initial creation
'
'***************************************************************************************
Option Explicit
Dim objShell, WshShell
Set objShell = CreateObject("Shell.Application")
Set WshShell = CreateObject("WScript.Shell")
objShell.ControlPanelItem("powercfg.cpl")
WScript.Sleep 500
WshShell.SendKeys "+{TAB}"
WScript.Sleep 500
WshShell.SendKeys "{RIGHT}"
WScript.Sleep 500
WshShell.SendKeys "{TAB 2}"
WScript.Sleep 500
WshShell.SendKeys "{UP 2}"
WScript.Sleep 500
WshShell.SendKeys "{ENTER}"
答案2
由于我无法找出适当的注册表项值,我最终只是编写了一个脚本来自动化对话框。由于我将 AutoIT 用于其他用途,所以我使用了它。希望这可以帮助其他人。
#include <GuiTab.au3>
; Start the System control panel
Run("rundll32.exe shell32.dll,Control_RunDLL powercfg.cpl,,3")
$title = "Power Options Properties"
$text = ""
WinWait( $title, $text)
If Not WinActive( $title, $text) Then WinActivate( $title, $text)
WinWaitActive( $title, $text)
;select the 'Advanced' tab
$hTab = ControlGetHandle( $title, $text, "[CLASS:SysTabControl32; INSTANCE:1]")
_GUICtrlTab_ClickTab($hTab, 1)
Sleep(10)
;set the combobox to 'Do nothing'
ControlCommand( $title, $text, "[CLASS:ComboBox; INSTANCE:2]", "SelectString", "Do nothing")
Sleep(10)
;click OK
ControlClick( $title, $text, "[CLASS:Button; INSTANCE:6]")
该脚本仅打开电源选项对话框,选择高级选项卡,将组合设置为“不执行任何操作”,然后按“确定”。