# Script to turn off keyboard shortcuts on Windows

Keyboard shortcuts are a convenient way to perform various actions quickly on devices. However, there may be situations where you want to turn off specific keyboard shortcuts based on your needs. In this document, we will explore scripts that allow you to disable or enable keyboard shortcuts across Windows devices and the Microsoft Edge app installed.

Whether you want to temporarily disable certain shortcuts or enable them, the scripts provide a flexible solution. Use Hexnode’s [Execute Custom Script](https://www.hexnode.com/mobile-device-management/help/executing-custom-scripts-for-windows/) feature to remotely deploy these scripts to multiple devices in no time.

 Disclaimer: 
The sample scripts provided below are adapted from third-party open-source sites.

 

PowerShell script to manage keyboard shortcuts on Windows
---------------------------------------------------------

### Disable keyboard shortcuts

Script to disable keyboard shortcuts on Windows

try { $status = New-PSDrive -PSProvider Registry -Name HKU -Root HKEY\_USERS Function RestrictShortcut($sid) { $policyPath = "HKU:\\${sid}\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer" # Check if the "Explorer" key exists if (!(Test-Path $policyPath)) { # Create the "Explorer" key New-Item -Path $policyPath -Force | Out-Null } New-ItemProperty -Path $policyPath -Name "NoWinKeys" -Value 1 -PropertyType DWORD -Force | Out-Null } $userDetails=Get-wmiobject win32\_useraccount | where-object{$\_.status -eq 'ok'} $loggedInUserCount = 0 foreach($user in $userDetails) { $sid=$user.SID $username = $user.Name if(Test-Path "HKU:\\${sid}") { Write-Host $username,"is signed-in to the device." Write-Host "Restricting Windows Shortcut for :",$username RestrictShortcut($sid) $loggedInUserCount++ } } if($loggedInUserCount -eq 0) { Write-Host "Policy hasn't applied to any user, this policy can only be applied when the user is logged in to the device" } else { Write-Host "Restart the device to review the changes." } } catch { Write-Host "Error occured while running script -> ",$\_.Exception.Message }

   1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

  try

{

 $status = New-PSDrive -PSProvider Registry -Name HKU -Root HKEY\_USERS

 Function RestrictShortcut($sid)

 {

 $policyPath = "HKU:\\${sid}\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer"

 \# Check if the "Explorer" key exists

 if (!(Test-Path $policyPath))

 {

 \# Create the "Explorer" key

 New-Item -Path $policyPath -Force | Out-Null

 }

 New-ItemProperty -Path $policyPath -Name "NoWinKeys" -Value 1 -PropertyType DWORD -Force | Out-Null

 }

 $userDetails=Get-wmiobject win32\_useraccount | where-object{$\_.status -eq 'ok'}

 $loggedInUserCount = 0

 foreach($user in $userDetails)

 {

 $sid=$user.SID

 $username = $user.Name

 if(Test-Path "HKU:\\${sid}")

 {

 Write-Host $username,"is signed-in to the device."

 Write-Host "Restricting Windows Shortcut for :",$username

 RestrictShortcut($sid)

 $loggedInUserCount++

 }

 }

 if($loggedInUserCount -eq 0)

 {

 Write-Host "Policy hasn't applied to any user, this policy can only be applied when the user is logged in to the device"

 }

 else

 {

 Write-Host "Restart the device to review the changes."

 }

}

catch

{

 Write-Host "Error occured while running script -> ",$\_.Exception.Message

}

   

 

  

The following keyboard shortcuts are disabled on Windows after executing the above script.

Shortcut keyFunctionWindows key + AOpen Quick SettingsWindows key + Ctrl + FSearch for PCs (if you’re on a network)Windows key + EOpen File ExplorerWindows key + H Launch voice typing Windows key + Pause/BreakOpen system informationWindows key + ROpen the Run dialog boxWindows key + SOpen searchWindows key + Shift + SCapture a screenshot of part of your screenWindows key + TCycle through apps on the taskbarWindows key + VOpen the clipboard historyWindows key + XOpen the Quick Link menuWindows key + Alt + RRecord video of the active game window (using Xbox Game Bar)Windows key + Shift + VSet focus to a notificationWindows key + numberOpen the desktop and launch the app pinned to the taskbar in the specified position indicated by ‘number’. If the app is already running, switch to that app.Windows key + Shift + numberOpen the desktop and initiate a new instance of the app pinned to the taskbar at the position indicated by ‘number’.### Enable keyboard shortcuts

Use the below script to enable all keyboard shortcuts on your devices.

Script to enable keyboard shortcuts on Windows

try { $status = New-PSDrive -PSProvider Registry -Name HKU -Root HKEY\_USERS Function RestrictShortcut($sid) { $policyPath = "HKU:\\${sid}\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\" $keyname = "Explorer" if(Test-Path "$policyPath\\$keyName") { Remove-Item -Path "$policyPath\\$keyName" -Recurse -Force } } $userDetails=Get-wmiobject win32\_useraccount | where-object{$\_.status -eq 'ok'} $loggedInUserCount = 0 foreach($user in $userDetails) { $sid=$user.SID $username = $user.Name if(Test-Path "HKU:\\${sid}") { Write-Host $username,"is signed-in to the device." Write-Host "Enabling Windows Shortcut for :",$username RestrictShortcut($sid) $loggedInUserCount++ } } if($loggedInUserCount -eq 0) { Write-Host "Policy hasn't applied to any user, this policy can only be applied when the user is logged in to the device" } else { Write-Host "Restart the device to review the changes." } } catch { Write-Host "Error occured while running script -> ",$\_.Exception.Message }

   1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

  try

{

 $status = New-PSDrive -PSProvider Registry -Name HKU -Root HKEY\_USERS

 Function RestrictShortcut($sid)

 {

 $policyPath = "HKU:\\${sid}\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\"

 $keyname = "Explorer"

 if(Test-Path "$policyPath\\$keyName")

 {

 Remove-Item -Path "$policyPath\\$keyName" -Recurse -Force

 }

 }

 $userDetails=Get-wmiobject win32\_useraccount | where-object{$\_.status -eq 'ok'}

 $loggedInUserCount = 0

 foreach($user in $userDetails)

 {

 $sid=$user.SID

 $username = $user.Name

 if(Test-Path "HKU:\\${sid}")

 {

 Write-Host $username,"is signed-in to the device."

 Write-Host "Enabling Windows Shortcut for :",$username

 RestrictShortcut($sid)

 $loggedInUserCount++

 } 

 }

 if($loggedInUserCount -eq 0)

 {

 Write-Host "Policy hasn't applied to any user, this policy can only be applied when the user is logged in to the device"

 }

 else

 {

 Write-Host "Restart the device to review the changes."

 }

}

catch

{

 Write-Host "Error occured while running script -> ",$\_.Exception.Message

}

   

 

  

 Notes: 
After successfully executing the script, it is necessary to restart the device for the keyboard shortcuts to take effect.

 

PowerShell script to manage keyboard shortcuts on the Edge browser
------------------------------------------------------------------

### Disable keyboard shortcuts on Microsoft Edge

Script to disable keyboard shortcuts on Microsoft Edge

try { $status = New-PSDrive -PSProvider Registry -Name HKU -Root HKEY\_USERS Function RestrictShortcut($sid) { $policyPath = "HKU:\\${sid}\\SOFTWARE\\Policies\\Microsoft\\Edge" $valueName = "ConfigureKeyboardShortcuts" $valueData = '{"disabled": \["open\_file", "save\_page", "new\_inprivate\_window", "duplicate\_tab", "dev\_tools", "web\_capture", "collections","profile", "print", "focus\_search", "home", "settings\_and\_more\_menu"\]}' # Check if the "Edge" key exists if (!(Test-Path $policyPath)) { # Create the "Edge" key New-Item -Path $policyPath -Force | Out-Null } New-ItemProperty -Path $policyPath -Name $valueName -Value $valueData -PropertyType String -Force | Out-Null } $userDetails=Get-wmiobject win32\_useraccount | where-object{$\_.status -eq 'ok'} $loggedInUserCount = 0 foreach($user in $userDetails) { $sid=$user.SID $username = $user.Name if(Test-Path "HKU:\\${sid}") { Write-Host $username,"is signed-in to the device." Write-Host "Restricting Edge Shortcut for :",$username RestrictShortcut($sid) $loggedInUserCount++ } } if($loggedInUserCount -eq 0) { Write-Host "Policy hasn't applied to any user, this policy can only be applied when the user is logged in to the device" } else { Write-Host "Restart the Edge to review the changes." } } catch { Write-Host "Error occured while running script -> ",$\_.Exception.Message }

   1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

  try

{

 $status = New-PSDrive -PSProvider Registry -Name HKU -Root HKEY\_USERS

 Function RestrictShortcut($sid)

 {

 $policyPath = "HKU:\\${sid}\\SOFTWARE\\Policies\\Microsoft\\Edge"

 $valueName = "ConfigureKeyboardShortcuts"

 $valueData = '{"disabled": \["open\_file", "save\_page", "new\_inprivate\_window", "duplicate\_tab", "dev\_tools", "web\_capture", "collections","profile", "print", "focus\_search", "home", "settings\_and\_more\_menu"\]}'

 \# Check if the "Edge" key exists

 if (!(Test-Path $policyPath))

 {

 \# Create the "Edge" key

 New-Item -Path $policyPath -Force | Out-Null

 }

 New-ItemProperty -Path $policyPath -Name $valueName -Value $valueData -PropertyType String -Force | Out-Null

 }

 $userDetails=Get-wmiobject win32\_useraccount | where-object{$\_.status -eq 'ok'}

 $loggedInUserCount = 0

 foreach($user in $userDetails)

 {

 $sid=$user.SID

 $username = $user.Name

 if(Test-Path "HKU:\\${sid}")

 {

 Write-Host $username,"is signed-in to the device."

 Write-Host "Restricting Edge Shortcut for :",$username

 RestrictShortcut($sid)

 $loggedInUserCount++

 }

 }

 if($loggedInUserCount -eq 0)

 {

 Write-Host "Policy hasn't applied to any user, this policy can only be applied when the user is logged in to the device"

 }

 else

 {

 Write-Host "Restart the Edge to review the changes."

 }

}

catch

{

 Write-Host "Error occured while running script -> ",$\_.Exception.Message

}

   

 

  

The keyboard shortcuts given in the table are disabled on Microsoft Edge after executing the above script.

Shortcut keyFunctionCTRL + E *or* CTRL + KOpen search query in the address barCTRL + OOpen a file from your computer in EdgeCTRL + PPrint the current web pageCTRL + SSave the current web page CTRL + SHIFT + IOpen Developer ToolsCTRL + SHIFT + KDuplicate the current tabCTRL + SHIFT + MSign in as a different user or browse as a GuestCTRL + SHIFT + N Open a new InPrivate windowCTRL + SHIFT + SSave the current webpage as a screenshotCTRL + SHIFT + YOpen Collections ALT + HOMEOpen your homepage in the current tabALT + EOpen the Edge browser menu### Enable keyboard shortcuts on Microsoft Edge

The below script enables all keyboard shortcuts on the Microsoft Edge browser.

Script to enable keyboard shortcuts on Microsoft Edge

try { $status = New-PSDrive -PSProvider Registry -Name HKU -Root HKEY\_USERS Function RestrictShortcut($sid) { $policyPath = "HKU:\\${sid}\\SOFTWARE\\Policies\\Microsoft" $keyname = "Edge" if(Test-Path "$policyPath\\$keyName") { Remove-Item -Path "$policyPath\\$keyName" -Recurse -Force } } $userDetails=Get-wmiobject win32\_useraccount | where-object{$\_.status -eq 'ok'} $loggedInUserCount = 0 foreach($user in $userDetails) { $sid=$user.SID $username = $user.Name if(Test-Path "HKU:\\${sid}") { Write-Host $username,"is signed-in to the device." Write-Host "Enabling Edge Shortcut for :",$username RestrictShortcut($sid) $loggedInUserCount++ } } if($loggedInUserCount -eq 0) { Write-Host "Policy hasn't applied to any user, this policy can only be applied when the user is logged in to the device" } else { Write-Host "Restart the Edge to review the changes." } } catch { Write-Host "Error occured while running script -> ",$\_.Exception.Message }

   1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

  try

{

 $status = New-PSDrive -PSProvider Registry -Name HKU -Root HKEY\_USERS

 Function RestrictShortcut($sid)

 {

 $policyPath = "HKU:\\${sid}\\SOFTWARE\\Policies\\Microsoft"

 $keyname = "Edge"

 if(Test-Path "$policyPath\\$keyName")

 {

 Remove-Item -Path "$policyPath\\$keyName" -Recurse -Force

 }

 }

 $userDetails=Get-wmiobject win32\_useraccount | where-object{$\_.status -eq 'ok'}

 $loggedInUserCount = 0

 foreach($user in $userDetails)

 {

 $sid=$user.SID

 $username = $user.Name

 if(Test-Path "HKU:\\${sid}")

 {

 Write-Host $username,"is signed-in to the device."

 Write-Host "Enabling Edge Shortcut for :",$username

 RestrictShortcut($sid)

 $loggedInUserCount++

 }

 }

 if($loggedInUserCount -eq 0)

 {

 Write-Host "Policy hasn't applied to any user, this policy can only be applied when the user is logged in to the device"

 }

 else

 {

 Write-Host "Restart the Edge to review the changes."

 }

}

catch

{

 Write-Host "Error occured while running script -> ",$\_.Exception.Message

}

   

 

  

 Notes:- After executing the script, it is necessary to restart the Microsoft Edge application to ensure that the changes take effect.
- The scripts will be effective for every user account that is currently logged in.
- The scripts will fail if there is no logged-in user on the device during execution.
- It is recommended to manually validate the script execution on a system before executing the action in bulk.
- Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.