Hey everyone so I would like to disable the physical power button on some machines I support. The users have a habit of pressing the power button even though we have disabled the software shutdown option through GPO. So is there a way to set this in powershell?
I have tried this:
powercfg -setacvalueindex db310065-829b-4671-9647-2261c00e86ef 4f971e89-eebd-4455-a8de-9e59040e7347 7648efa3-dd9c-4e3e-b566-50f929386280 0
and this:
powercfg -setacvalueindex 381b4222-f694-41f0-9685-ff5bb260df2e 4f971e89-eebd-4455-a8de-9e59040e7347 7648efa3-dd9c-4e3e-b566-50f929386280 0
The first is a Power scheme under config man and the second is under High performance.
These two commands appear to change the setting but when I press the power button the machine still shuts off.
I have also tried this script:
Function Set-OSCPowerButtonAction { Param ( [Parameter(Mandatory = $true,Position = 0)] [ValidateSet("LogOff", "SwitchUser", "Lock","Restart","Sleep","Hibernate","ShutDown")] [String]$Action ) Switch($Action) { "SwitchUser" { ChangebuttonAction 0x00000100 } "LogOff" { ChangebuttonAction 0x00000001 } "Lock" { ChangebuttonAction 0x00000200 } "Restart" { ChangebuttonAction 0x00000004 } "Sleep" { ChangebuttonAction 0x00000010 } "Hibernate" { ChangebuttonAction 0x00000040 } "Shutdown" { ChangebuttonAction 0x00000002 } } GetChoice } Function ChangebuttonAction($value) { $Regpath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" $KetExist = Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name "Start_PowerButtonAction" -ErrorAction SilentlyContinue If($KetExist) { Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name "Start_PowerButtonAction" -Value $value } Else { New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name "Start_PowerButtonAction" -Value $value -PropertyType Dword } } Function GetChoice { #Prompt message $Caption = "Restart the computer." $Message = "It will take effect after restart, do you want to restart right now?" $Choices = [System.Management.Automation.Host.ChoiceDescription[]]` @("&Yes","&No") [Int]$DefaultChoice = 0 $ChoiceRTN = $Host.UI.PromptForChoice($Caption, $Message, $Choices, $DefaultChoice) Switch ($ChoiceRTN) { 0 {shutdown -t 0 -r } 1 {break} } }
None of these seem to work is this possible to do? Thanks for any help!