Skip to content

Instantly share code, notes, and snippets.

@phillip-haydon
Created June 7, 2018 10:29
Show Gist options
  • Save phillip-haydon/46435fddc9d41e6e8bf614e44aa3495e to your computer and use it in GitHub Desktop.
Save phillip-haydon/46435fddc9d41e6e8bf614e44aa3495e to your computer and use it in GitHub Desktop.
Powershell - Disable Shutdown / Restart buttons on Windows
Install-Module -Name PolicyFileEditor -SkipPublisherCheck -Force
$UserDir = "$env:windir\system32\GroupPolicy\User\registry.pol"
# After manually setting the values in Local Group Policy Editor (gpedit.msc), extract the values our so we can set them
# Get-PolicyFileEntry -Path $UserDir -All
# Disable the Shutdown / Restart options
# http://brandonpadgett.com/powershell/Local-gpo-powershell/
# http://blog.willbeattie.com/2010/01/disabling-shut-down-button-on-windows.html
$RegPath = 'Software\Microsoft\Windows\CurrentVersion\Policies\Explorer'
$RegName = 'NoClose'
$RegData = '1'
$RegType = 'DWord'
Set-PolicyFileEntry -Path $UserDir -Key $RegPath -ValueName $RegName -Data $RegData -Type $RegType
@deftoner
Copy link

deftoner commented Feb 14, 2023

i want to change it for the current user instead of local machine. how to change it and get the changes reflected immediately.

Also i used process monitor to scan for the changes, GUID were involved in HKCU. so what could be best api to call to make the changes

There is no current user or per local user policy, its at machine level. You can apply the GPO via machine or via user, but will apply to the computer itself, not a user.

Its a switch that alter the behavior of the menu for all users.

If you are on an Active Directory network, you can apply this GPO to the user, so will apply when that user logs to the machine. but other users not. But again, its a local machine GPO applied when the user logs in.

@AnCarsenat
Copy link

this not work check out mine program : https://github.com/AnCarsenat/Disable-power-button

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment